1 USING: accessors http http.client http.client.private
2 io.streams.string kernel namespaces sequences splitting
6 { "foo.txt" } [ "http://www.paulgraham.com/foo.txt" download-name ] unit-test
7 { "foo.txt" } [ "http://www.arc.com/foo.txt?xxx" download-name ] unit-test
8 { "foo.txt" } [ "http://www.arc.com/foo.txt/" download-name ] unit-test
9 { "www.arc.com" } [ "http://www.arc.com////" download-name ] unit-test
13 { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
14 { proxy-url T{ url } }
18 { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
22 "http://www.apple.com/index.html"
28 { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
29 { proxy-url T{ url } }
33 { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
37 "https://www.amazon.com/index.html"
41 { "HEAD" } [ "http://google.com" <head-request> method>> ] unit-test
42 { "DELETE" } [ "http://arc.com" <delete-request> method>> ] unit-test
43 { "TRACE" } [ "http://concatenative.org" <trace-request> method>> ] unit-test
44 { "OPTIONS" } [ "http://factorcode.org" <options-request> method>> ] unit-test
46 ! Do not re-enable this for the test suite.
47 ! We should replace this with a similar test that does not
48 ! hit the velox.ch website.
50 ! "https://alice.sni.velox.ch" http-get nip
51 ! [ "Great!" swap subseq? ]
52 ! [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
57 "HTTP/1.1 200 Document follows"
59 "content-type: text/html; charset=UTF-8"
60 "date: Wed, 12 Oct 2011 18:57:49 GMT"
61 "server: Factor http.server"
62 } [ join-lines ] [ "\r\n" join ] bi
63 [ [ read-response ] with-string-reader ] same?
66 { "www.google.com:8080" } [
67 URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
70 { "/index.html?bar=baz" } [
71 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
77 { "/index.html?bar=baz" } [
78 "https://user:pass@www.apple.com/index.html?bar=baz#foo"
84 { "http://www.apple.com/index.html?bar=baz" } [
85 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
87 "http://localhost:3128" >>proxy-url
91 { "www.apple.com:80" } [
92 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
93 "CONNECT" <client-request>
98 { "www.apple.com:443" } [
99 "https://www.apple.com/index.html"
100 "CONNECT" <client-request>
107 "www.google.fr" <get-request> no-proxy?
113 "www.google.fr" <get-request> no-proxy?
118 "foo,,bar" "no_proxy" [
119 "www.google.fr" <get-request> no-proxy?
124 "foo,www.google.fr,bar" "no_proxy" [
125 "www.google.fr" <get-request> no-proxy?
129 ! TODO support 192.168.0.16/4 ?
130 CONSTANT: classic-proxy-settings H{
131 { "http.proxy" "http://proxy.private:3128" }
132 { "https.proxy" "http://proxysec.private:3128" }
133 { "no_proxy" "localhost,127.0.0.1,.allprivate,.a.subprivate,b.subprivate" }
137 classic-proxy-settings [
138 "localhost" "GET" <client-request> ?default-proxy proxy-url>>
143 classic-proxy-settings [
144 "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
148 { URL" http://proxy.private:3128" } [
149 classic-proxy-settings [
150 "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
155 classic-proxy-settings [
156 "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
161 classic-proxy-settings [
162 "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
166 { URL" http://proxy.private:3128" } [
167 classic-proxy-settings [
168 "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
173 classic-proxy-settings [
174 "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
179 classic-proxy-settings [
180 "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
184 { URL" http://proxy.private:3128" } [
185 classic-proxy-settings [
186 "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
190 { URL" http://proxy.private:3128" } [
191 classic-proxy-settings [
192 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
196 { URL" //localhost:3128" } [
197 { { "http.proxy" "//localhost:3128" } } [
198 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
202 { URL" //localhost:3128" } [
203 "google.com" "GET" <client-request>
204 URL" //localhost:3128" >>proxy-url ?default-proxy proxy-url>>
207 { URL" //localhost:3128" } [
208 "google.com" "GET" <client-request>
209 "//localhost:3128" >>proxy-url ?default-proxy proxy-url>>
212 { URL" http://proxysec.private:3128" } [
213 classic-proxy-settings [
214 "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
218 { URL" http://proxy.private:3128" } [
219 classic-proxy-settings [
220 "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
225 <url> 3128 >>port "http.proxy" [
226 "http://www.google.com" "GET" <client-request> ?default-proxy
228 ] [ invalid-proxy? ] must-fail-with
230 ! This url is misparsed bu request-url can fix it
233 { host "www.google.com" }
236 } } [ "www.google.com" request-url ] unit-test
238 ! This one is not fixable, leave it as it is
239 { T{ url } } [ "" request-url ] unit-test