]> gitweb.factorcode.org Git - factor.git/blob - basis/http/client/client-tests.factor
more test IN: cleanup.
[factor.git] / basis / http / client / client-tests.factor
1 USING: accessors http http.client http.client.private
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
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.
51 ! { t } [
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
55 ! ] unit-test
56
57 { t } [
58     {
59         "HTTP/1.1 200 Document follows"
60         "connection: close"
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?
66 ] unit-test
67
68 { "www.google.com:8080" } [
69     URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
70 ] unit-test
71
72 { "/index.html?bar=baz" } [
73     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
74     <get-request>
75         f >>proxy-url
76     request-uri
77 ] unit-test
78
79 { "/index.html?bar=baz" } [
80     "https://user:pass@www.apple.com/index.html?bar=baz#foo"
81     <get-request>
82         f >>proxy-url
83     request-uri
84 ] unit-test
85
86 { "http://www.apple.com/index.html?bar=baz" } [
87     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
88     <get-request>
89         "http://localhost:3128" >>proxy-url
90     request-uri
91 ] unit-test
92
93 { "www.apple.com:80" } [
94     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
95     "CONNECT" <client-request>
96         f >>proxy-url
97     request-uri
98 ] unit-test
99
100 { "www.apple.com:443" } [
101     "https://www.apple.com/index.html"
102     "CONNECT" <client-request>
103         f >>proxy-url
104      request-uri
105 ] unit-test
106
107 { f } [
108     "" "no_proxy" [
109         "www.google.fr" <get-request> no-proxy?
110     ] with-variable
111 ] unit-test
112
113 { f } [
114     "," "no_proxy" [
115         "www.google.fr" <get-request> no-proxy?
116     ] with-variable
117 ] unit-test
118
119 { f } [
120     "foo,,bar" "no_proxy" [
121         "www.google.fr" <get-request> no-proxy?
122     ] with-variable
123 ] unit-test
124
125 { t } [
126     "foo,www.google.fr,bar" "no_proxy" [
127         "www.google.fr" <get-request> no-proxy?
128     ] with-variable
129 ] unit-test
130
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" }
136 }
137
138 { f } [
139     classic-proxy-settings [
140        "localhost" "GET" <client-request> ?default-proxy proxy-url>>
141     ] with-variables
142 ] unit-test
143
144 { f } [
145     classic-proxy-settings [
146        "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
147     ] with-variables
148 ] unit-test
149
150 { URL" http://proxy.private:3128" } [
151     classic-proxy-settings [
152        "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
153     ] with-variables
154 ] unit-test
155
156 { f } [
157     classic-proxy-settings [
158        "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
159     ] with-variables
160 ] unit-test
161
162 { f } [
163     classic-proxy-settings [
164        "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
165     ] with-variables
166 ] unit-test
167
168 { URL" http://proxy.private:3128" } [
169     classic-proxy-settings [
170        "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
171     ] with-variables
172 ] unit-test
173
174 { f } [
175     classic-proxy-settings [
176        "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
177     ] with-variables
178 ] unit-test
179
180 { f } [
181     classic-proxy-settings [
182        "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
183     ] with-variables
184 ] unit-test
185
186 { URL" http://proxy.private:3128" } [
187     classic-proxy-settings [
188        "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
189     ] with-variables
190 ] unit-test
191
192 { URL" http://proxy.private:3128" } [
193     classic-proxy-settings [
194        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
195     ] with-variables
196 ] unit-test
197
198 { URL" http://localhost:3128" } [
199     { { "http.proxy" "localhost:3128" } } [
200        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
201     ] with-variables
202 ] unit-test
203
204 { URL" http://localhost:3128" } [
205     "google.com" "GET" <client-request>
206     URL" localhost:3128" >>proxy-url ?default-proxy proxy-url>>
207 ] unit-test
208
209 { URL" http://localhost:3128" } [
210     "google.com" "GET" <client-request>
211     "localhost:3128" >>proxy-url ?default-proxy proxy-url>>
212 ] unit-test
213
214 { URL" http://proxysec.private:3128" } [
215     classic-proxy-settings [
216        "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
217     ] with-variables
218 ] unit-test
219
220 { URL" http://proxy.private:3128" } [
221     classic-proxy-settings [
222        "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
223     ] with-variables
224 ] unit-test
225
226 [
227     <url> 3128 >>port "http.proxy" [
228        "http://www.google.com" "GET" <client-request> ?default-proxy
229     ] with-variable
230 ] [ invalid-proxy? ] must-fail-with
231
232 ! This url is misparsed bu request-url can fix it
233 { T{ url
234    { protocol "http" }
235    { host "www.google.com" }
236    { path "/" }
237    { port 80 }
238 } } [ "www.google.com" request-url ] unit-test
239
240 ! This one is not fixable, leave it as it is
241 { T{ url } } [ "" request-url ] unit-test