]> gitweb.factorcode.org Git - factor.git/blob - basis/http/client/client-tests.factor
http.client, allow to use http proxies
[factor.git] / basis / http / client / client-tests.factor
1 USING: accessors io.sockets.secure http.client http.client.private http
2 io.streams.string kernel namespaces sequences tools.test urls ;
3 IN: http.client.tests
4
5 { "localhost" f } [ "localhost" parse-host ] unit-test
6 { "localhost" 8888 } [ "localhost:8888" parse-host ] unit-test
7
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
12
13 {
14     T{ request
15         { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
16         { proxy-url T{ url } }
17         { method "GET" }
18         { version "1.1" }
19         { cookies V{ } }
20         { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
21         { redirects 10 }
22     }
23 } [
24     "http://www.apple.com/index.html"
25     <get-request>
26 ] unit-test
27
28 {
29     T{ request
30         { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
31         { proxy-url T{ url } }
32         { method "GET" }
33         { version "1.1" }
34         { cookies V{ } }
35         { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
36         { redirects 10 }
37     }
38 } [
39     "https://www.amazon.com/index.html"
40     <get-request>
41 ] unit-test
42
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
47 { t } [
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
51 ] unit-test
52
53 { t } [
54     {
55         "HTTP/1.1 200 Document follows"
56         "connection: close"
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?
62 ] unit-test
63
64 { "www.google.com:8080" } [
65     URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
66 ] unit-test
67
68 { "/index.html?bar=baz" } [
69     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
70     <get-request>
71         f >>proxy-url
72     request-uri
73 ] unit-test
74
75 { "/index.html?bar=baz" } [
76     "https://user:pass@www.apple.com/index.html?bar=baz#foo"
77     <get-request>
78         f >>proxy-url
79     request-uri
80 ] unit-test
81
82 { "http://www.apple.com/index.html?bar=baz" } [
83     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
84     <get-request>
85         "http://localhost:3128" >>proxy-url
86     request-uri
87 ] unit-test
88
89 { "www.apple.com:80" } [
90     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
91     "CONNECT" <client-request>
92         f >>proxy-url
93     request-uri
94 ] unit-test
95
96 { "www.apple.com:443" } [
97     "https://www.apple.com/index.html"
98     "CONNECT" <client-request>
99         f >>proxy-url
100      request-uri
101 ] unit-test
102
103 { f } [
104     "" "no_proxy" [
105         "www.google.fr" <get-request> no-proxy?
106     ] with-variable
107 ] unit-test
108
109 { f } [
110     "," "no_proxy" [
111         "www.google.fr" <get-request> no-proxy?
112     ] with-variable
113 ] unit-test
114
115 { f } [
116     "foo,,bar" "no_proxy" [
117         "www.google.fr" <get-request> no-proxy?
118     ] with-variable
119 ] unit-test
120
121 { t } [
122     "foo,www.google.fr,bar" "no_proxy" [
123         "www.google.fr" <get-request> no-proxy?
124     ] with-variable
125 ] unit-test
126
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" }
132 }
133
134 { f } [
135     classic-proxy-settings [
136        "localhost" "GET" <client-request> ?default-proxy proxy-url>>
137     ] with-variables
138 ] unit-test
139
140 { f } [
141     classic-proxy-settings [
142        "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
143     ] with-variables
144 ] unit-test
145
146 { URL" http://proxy.private:3128" } [
147     classic-proxy-settings [
148        "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
149     ] with-variables
150 ] unit-test
151
152 { f } [
153     classic-proxy-settings [
154        "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
155     ] with-variables
156 ] unit-test
157
158 { f } [
159     classic-proxy-settings [
160        "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
161     ] with-variables
162 ] unit-test
163
164 { URL" http://proxy.private:3128" } [
165     classic-proxy-settings [
166        "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
167     ] with-variables
168 ] unit-test
169
170 { f } [
171     classic-proxy-settings [
172        "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
173     ] with-variables
174 ] unit-test
175
176 { f } [
177     classic-proxy-settings [
178        "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
179     ] with-variables
180 ] unit-test
181
182 { URL" http://proxy.private:3128" } [
183     classic-proxy-settings [
184        "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
185     ] with-variables
186 ] unit-test
187
188 { URL" http://proxy.private:3128" } [
189     classic-proxy-settings [
190        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
191     ] with-variables
192 ] unit-test
193
194 { URL" http://proxysec.private:3128" } [
195     classic-proxy-settings [
196        "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
197     ] with-variables
198 ] unit-test
199
200 { URL" http://proxy.private:3128" } [
201     classic-proxy-settings [
202        "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
203     ] with-variables
204 ] unit-test