1 USING: accessors io.sockets.secure http.client http.client.private http
2 io.streams.string kernel namespaces sequences tools.test urls ;
5 { "localhost" f } [ "localhost" parse-host ] unit-test
6 { "localhost" 8888 } [ "localhost:8888" parse-host ] unit-test
8 { "foo.txt" } [ "http://www.paulgraham.com/foo.txt" download-name ] unit-test
9 { "foo.txt" } [ "http://www.arc.com/foo.txt?xxx" download-name ] unit-test
10 { "foo.txt" } [ "http://www.arc.com/foo.txt/" download-name ] unit-test
11 { "www.arc.com" } [ "http://www.arc.com////" download-name ] unit-test
15 { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
16 { proxy-url T{ url } }
20 { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
24 "http://www.apple.com/index.html"
30 { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
31 { proxy-url T{ url } }
35 { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
39 "https://www.amazon.com/index.html"
43 { "HEAD" } [ "http://google.com" <head-request> method>> ] unit-test
44 { "DELETE" } [ "http://arc.com" <delete-request> method>> ] unit-test
45 { "TRACE" } [ "http://concatenative.org" <trace-request> method>> ] unit-test
46 { "OPTIONS" } [ "http://factorcode.org" <options-request> method>> ] unit-test
48 ! Do not re-enable this for the test suite.
49 ! We should replace this with a similar test that does not
50 ! hit the velox.ch website.
52 ! "https://alice.sni.velox.ch" http-get nip
53 ! [ "Great!" swap subseq? ]
54 ! [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
59 "HTTP/1.1 200 Document follows"
61 "content-type: text/html; charset=UTF-8"
62 "date: Wed, 12 Oct 2011 18:57:49 GMT"
63 "server: Factor http.server"
64 } [ "\n" join ] [ "\r\n" join ] bi
65 [ [ read-response ] with-string-reader ] same?
68 { "www.google.com:8080" } [
69 URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
72 { "/index.html?bar=baz" } [
73 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
79 { "/index.html?bar=baz" } [
80 "https://user:pass@www.apple.com/index.html?bar=baz#foo"
86 { "http://www.apple.com/index.html?bar=baz" } [
87 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
89 "http://localhost:3128" >>proxy-url
93 { "www.apple.com:80" } [
94 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
95 "CONNECT" <client-request>
100 { "www.apple.com:443" } [
101 "https://www.apple.com/index.html"
102 "CONNECT" <client-request>
109 "www.google.fr" <get-request> no-proxy?
115 "www.google.fr" <get-request> no-proxy?
120 "foo,,bar" "no_proxy" [
121 "www.google.fr" <get-request> no-proxy?
126 "foo,www.google.fr,bar" "no_proxy" [
127 "www.google.fr" <get-request> no-proxy?
131 ! TODO support 192.168.0.16/4 ?
132 CONSTANT: classic-proxy-settings H{
133 { "http.proxy" "http://proxy.private:3128" }
134 { "https.proxy" "http://proxysec.private:3128" }
135 { "no_proxy" "localhost,127.0.0.1,.allprivate,.a.subprivate,b.subprivate" }
139 classic-proxy-settings [
140 "localhost" "GET" <client-request> ?default-proxy proxy-url>>
145 classic-proxy-settings [
146 "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
150 { URL" http://proxy.private:3128" } [
151 classic-proxy-settings [
152 "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
157 classic-proxy-settings [
158 "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
163 classic-proxy-settings [
164 "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
168 { URL" http://proxy.private:3128" } [
169 classic-proxy-settings [
170 "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
175 classic-proxy-settings [
176 "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
181 classic-proxy-settings [
182 "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
186 { URL" http://proxy.private:3128" } [
187 classic-proxy-settings [
188 "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
192 { URL" http://proxy.private:3128" } [
193 classic-proxy-settings [
194 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
198 { URL" http://localhost:3128" } [
199 { { "http.proxy" "localhost:3128" } } [
200 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
204 { URL" http://localhost:3128" } [
205 "google.com" "GET" <client-request>
206 URL" localhost:3128" >>proxy-url ?default-proxy proxy-url>>
209 { URL" http://localhost:3128" } [
210 "google.com" "GET" <client-request>
211 "localhost:3128" >>proxy-url ?default-proxy proxy-url>>
214 { URL" http://proxysec.private:3128" } [
215 classic-proxy-settings [
216 "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
220 { URL" http://proxy.private:3128" } [
221 classic-proxy-settings [
222 "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
227 <url> 3128 >>port "http.proxy" [
228 "http://www.google.com" "GET" <client-request> ?default-proxy
230 ] [ invalid-proxy? ] must-fail-with
232 ! This url is misparsed bu request-url can fix it
235 { host "www.google.com" }
238 } } [ "www.google.com" request-url ] unit-test
240 ! This one is not fixable, leave it as it is
241 { T{ url } } [ "" request-url ] unit-test