1 USING: accessors http http.client http.client.private
2 io.streams.string kernel namespaces sequences tools.test urls ;
5 { "foo.txt" } [ "http://www.paulgraham.com/foo.txt" download-name ] unit-test
6 { "foo.txt" } [ "http://www.arc.com/foo.txt?xxx" download-name ] unit-test
7 { "foo.txt" } [ "http://www.arc.com/foo.txt/" download-name ] unit-test
8 { "www.arc.com" } [ "http://www.arc.com////" download-name ] unit-test
12 { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
13 { proxy-url T{ url } }
17 { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
21 "http://www.apple.com/index.html"
27 { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
28 { proxy-url T{ url } }
32 { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
36 "https://www.amazon.com/index.html"
40 { "HEAD" } [ "http://google.com" <head-request> method>> ] unit-test
41 { "DELETE" } [ "http://arc.com" <delete-request> method>> ] unit-test
42 { "TRACE" } [ "http://concatenative.org" <trace-request> method>> ] unit-test
43 { "OPTIONS" } [ "http://factorcode.org" <options-request> method>> ] unit-test
45 ! Do not re-enable this for the test suite.
46 ! We should replace this with a similar test that does not
47 ! hit the velox.ch website.
49 ! "https://alice.sni.velox.ch" http-get nip
50 ! [ "Great!" swap subseq? ]
51 ! [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
56 "HTTP/1.1 200 Document follows"
58 "content-type: text/html; charset=UTF-8"
59 "date: Wed, 12 Oct 2011 18:57:49 GMT"
60 "server: Factor http.server"
61 } [ join-lines ] [ "\r\n" join ] bi
62 [ [ read-response ] with-string-reader ] same?
65 { "www.google.com:8080" } [
66 URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
69 { "/index.html?bar=baz" } [
70 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
76 { "/index.html?bar=baz" } [
77 "https://user:pass@www.apple.com/index.html?bar=baz#foo"
83 { "http://www.apple.com/index.html?bar=baz" } [
84 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
86 "http://localhost:3128" >>proxy-url
90 { "www.apple.com:80" } [
91 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
92 "CONNECT" <client-request>
97 { "www.apple.com:443" } [
98 "https://www.apple.com/index.html"
99 "CONNECT" <client-request>
106 "www.google.fr" <get-request> no-proxy?
112 "www.google.fr" <get-request> no-proxy?
117 "foo,,bar" "no_proxy" [
118 "www.google.fr" <get-request> no-proxy?
123 "foo,www.google.fr,bar" "no_proxy" [
124 "www.google.fr" <get-request> no-proxy?
128 ! TODO support 192.168.0.16/4 ?
129 CONSTANT: classic-proxy-settings H{
130 { "http.proxy" "http://proxy.private:3128" }
131 { "https.proxy" "http://proxysec.private:3128" }
132 { "no_proxy" "localhost,127.0.0.1,.allprivate,.a.subprivate,b.subprivate" }
136 classic-proxy-settings [
137 "localhost" "GET" <client-request> ?default-proxy proxy-url>>
142 classic-proxy-settings [
143 "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
147 { URL" http://proxy.private:3128" } [
148 classic-proxy-settings [
149 "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
154 classic-proxy-settings [
155 "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
160 classic-proxy-settings [
161 "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
165 { URL" http://proxy.private:3128" } [
166 classic-proxy-settings [
167 "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
172 classic-proxy-settings [
173 "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
178 classic-proxy-settings [
179 "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
183 { URL" http://proxy.private:3128" } [
184 classic-proxy-settings [
185 "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
189 { URL" http://proxy.private:3128" } [
190 classic-proxy-settings [
191 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
195 { URL" //localhost:3128" } [
196 { { "http.proxy" "//localhost:3128" } } [
197 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
201 { URL" //localhost:3128" } [
202 "google.com" "GET" <client-request>
203 URL" //localhost:3128" >>proxy-url ?default-proxy proxy-url>>
206 { URL" //localhost:3128" } [
207 "google.com" "GET" <client-request>
208 "//localhost:3128" >>proxy-url ?default-proxy proxy-url>>
211 { URL" http://proxysec.private:3128" } [
212 classic-proxy-settings [
213 "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
217 { URL" http://proxy.private:3128" } [
218 classic-proxy-settings [
219 "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
224 <url> 3128 >>port "http.proxy" [
225 "http://www.google.com" "GET" <client-request> ?default-proxy
227 ] [ invalid-proxy? ] must-fail-with
229 ! This url is misparsed bu request-url can fix it
232 { host "www.google.com" }
235 } } [ "www.google.com" request-url ] unit-test
237 ! This one is not fixable, leave it as it is
238 { T{ url } } [ "" request-url ] unit-test