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 "https://alice.sni.velox.ch" http-get nip
49 [ "Great!" swap subseq? ]
50 [ "TLS SNI Test Site: alice.sni.velox.ch" swap subseq? ] bi and
55 "HTTP/1.1 200 Document follows"
57 "content-type: text/html; charset=UTF-8"
58 "date: Wed, 12 Oct 2011 18:57:49 GMT"
59 "server: Factor http.server"
60 } [ "\n" join ] [ "\r\n" join ] bi
61 [ [ read-response ] with-string-reader ] same?
64 { "www.google.com:8080" } [
65 URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
68 { "/index.html?bar=baz" } [
69 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
75 { "/index.html?bar=baz" } [
76 "https://user:pass@www.apple.com/index.html?bar=baz#foo"
82 { "http://www.apple.com/index.html?bar=baz" } [
83 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
85 "http://localhost:3128" >>proxy-url
89 { "www.apple.com:80" } [
90 "http://user:pass@www.apple.com/index.html?bar=baz#foo"
91 "CONNECT" <client-request>
96 { "www.apple.com:443" } [
97 "https://www.apple.com/index.html"
98 "CONNECT" <client-request>
105 "www.google.fr" <get-request> no-proxy?
111 "www.google.fr" <get-request> no-proxy?
116 "foo,,bar" "no_proxy" [
117 "www.google.fr" <get-request> no-proxy?
122 "foo,www.google.fr,bar" "no_proxy" [
123 "www.google.fr" <get-request> no-proxy?
127 ! TODO support 192.168.0.16/4 ?
128 CONSTANT: classic-proxy-settings H{
129 { "http.proxy" "http://proxy.private:3128" }
130 { "https.proxy" "http://proxysec.private:3128" }
131 { "no_proxy" "localhost,127.0.0.1,.allprivate,.a.subprivate,b.subprivate" }
135 classic-proxy-settings [
136 "localhost" "GET" <client-request> ?default-proxy proxy-url>>
141 classic-proxy-settings [
142 "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
146 { URL" http://proxy.private:3128" } [
147 classic-proxy-settings [
148 "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
153 classic-proxy-settings [
154 "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
159 classic-proxy-settings [
160 "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
164 { URL" http://proxy.private:3128" } [
165 classic-proxy-settings [
166 "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
171 classic-proxy-settings [
172 "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
177 classic-proxy-settings [
178 "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
182 { URL" http://proxy.private:3128" } [
183 classic-proxy-settings [
184 "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
188 { URL" http://proxy.private:3128" } [
189 classic-proxy-settings [
190 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
194 { URL" http://localhost:3128" } [
195 { { "http.proxy" "localhost:3128" } } [
196 "google.com" "GET" <client-request> ?default-proxy proxy-url>>
200 { URL" http://localhost:3128" } [
201 "google.com" "GET" <client-request>
202 URL" localhost:3128" >>proxy-url ?default-proxy proxy-url>>
205 { URL" http://localhost:3128" } [
206 "google.com" "GET" <client-request>
207 "localhost:3128" >>proxy-url ?default-proxy proxy-url>>
210 { URL" http://proxysec.private:3128" } [
211 classic-proxy-settings [
212 "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
216 { URL" http://proxy.private:3128" } [
217 classic-proxy-settings [
218 "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
223 <url> 3128 >>port "http.proxy" [
224 "http://www.google.com" "GET" <client-request> ?default-proxy
226 ] [ invalid-proxy? ] must-fail-with
228 ! This url is misparsed bu request-url can fix it
231 { host "www.google.com" }
234 } } [ "www.google.com" request-url ] unit-test
236 ! This one is not fixable, leave it as it is
237 { T{ url } } [ "" request-url ] unit-test