]> gitweb.factorcode.org Git - factor.git/blob - basis/http/client/client-tests.factor
f792d3491a66e7b59b1c10fdac3912b02bbc9a95
[factor.git] / basis / http / client / client-tests.factor
1 USING: accessors http http.client http.client.private
2 io.streams.string kernel namespaces sequences splitting
3 tools.test urls ;
4 IN: http.client.tests
5
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
10
11 {
12     T{ request
13         { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
14         { proxy-url T{ url } }
15         { method "GET" }
16         { version "1.1" }
17         { cookies V{ } }
18         { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
19         { redirects 10 }
20     }
21 } [
22     "http://www.apple.com/index.html"
23     <get-request>
24 ] unit-test
25
26 {
27     T{ request
28         { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
29         { proxy-url T{ url } }
30         { method "GET" }
31         { version "1.1" }
32         { cookies V{ } }
33         { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
34         { redirects 10 }
35     }
36 } [
37     "https://www.amazon.com/index.html"
38     <get-request>
39 ] unit-test
40
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
45
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.
49 ! { t } [
50     ! "https://alice.sni.velox.ch" http-get nip
51     ! [ "Great!" subseq-index? ]
52     ! [ "TLS SNI Test Site: alice.sni.velox.ch" subseq-index? ] bi and
53 ! ] unit-test
54
55 { t } [
56     {
57         "HTTP/1.1 200 Document follows"
58         "connection: close"
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?
64 ] unit-test
65
66 { "www.google.com:8080" } [
67     URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
68 ] unit-test
69
70 { "/index.html?bar=baz" } [
71     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
72     <get-request>
73         f >>proxy-url
74     request-uri
75 ] unit-test
76
77 { "/index.html?bar=baz" } [
78     "https://user:pass@www.apple.com/index.html?bar=baz#foo"
79     <get-request>
80         f >>proxy-url
81     request-uri
82 ] unit-test
83
84 { "http://www.apple.com/index.html?bar=baz" } [
85     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
86     <get-request>
87         "http://localhost:3128" >>proxy-url
88     request-uri
89 ] unit-test
90
91 { "www.apple.com:80" } [
92     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
93     "CONNECT" <client-request>
94         f >>proxy-url
95     request-uri
96 ] unit-test
97
98 { "www.apple.com:443" } [
99     "https://www.apple.com/index.html"
100     "CONNECT" <client-request>
101         f >>proxy-url
102      request-uri
103 ] unit-test
104
105 { f } [
106     "" "no_proxy" [
107         "www.google.fr" <get-request> no-proxy?
108     ] with-variable
109 ] unit-test
110
111 { f } [
112     "," "no_proxy" [
113         "www.google.fr" <get-request> no-proxy?
114     ] with-variable
115 ] unit-test
116
117 { f } [
118     "foo,,bar" "no_proxy" [
119         "www.google.fr" <get-request> no-proxy?
120     ] with-variable
121 ] unit-test
122
123 { t } [
124     "foo,www.google.fr,bar" "no_proxy" [
125         "www.google.fr" <get-request> no-proxy?
126     ] with-variable
127 ] unit-test
128
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" }
134 }
135
136 { f } [
137     classic-proxy-settings [
138        "localhost" "GET" <client-request> ?default-proxy proxy-url>>
139     ] with-variables
140 ] unit-test
141
142 { f } [
143     classic-proxy-settings [
144        "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
145     ] with-variables
146 ] unit-test
147
148 { URL" http://proxy.private:3128" } [
149     classic-proxy-settings [
150        "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
151     ] with-variables
152 ] unit-test
153
154 { f } [
155     classic-proxy-settings [
156        "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
157     ] with-variables
158 ] unit-test
159
160 { f } [
161     classic-proxy-settings [
162        "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
163     ] with-variables
164 ] unit-test
165
166 { URL" http://proxy.private:3128" } [
167     classic-proxy-settings [
168        "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
169     ] with-variables
170 ] unit-test
171
172 { f } [
173     classic-proxy-settings [
174        "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
175     ] with-variables
176 ] unit-test
177
178 { f } [
179     classic-proxy-settings [
180        "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
181     ] with-variables
182 ] unit-test
183
184 { URL" http://proxy.private:3128" } [
185     classic-proxy-settings [
186        "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
187     ] with-variables
188 ] unit-test
189
190 { URL" http://proxy.private:3128" } [
191     classic-proxy-settings [
192        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
193     ] with-variables
194 ] unit-test
195
196 { URL" //localhost:3128" } [
197     { { "http.proxy" "//localhost:3128" } } [
198        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
199     ] with-variables
200 ] unit-test
201
202 { URL" //localhost:3128" } [
203     "google.com" "GET" <client-request>
204     URL" //localhost:3128" >>proxy-url ?default-proxy proxy-url>>
205 ] unit-test
206
207 { URL" //localhost:3128" } [
208     "google.com" "GET" <client-request>
209     "//localhost:3128" >>proxy-url ?default-proxy proxy-url>>
210 ] unit-test
211
212 { URL" http://proxysec.private:3128" } [
213     classic-proxy-settings [
214        "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
215     ] with-variables
216 ] unit-test
217
218 { URL" http://proxy.private:3128" } [
219     classic-proxy-settings [
220        "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
221     ] with-variables
222 ] unit-test
223
224 [
225     <url> 3128 >>port "http.proxy" [
226        "http://www.google.com" "GET" <client-request> ?default-proxy
227     ] with-variable
228 ] [ invalid-proxy? ] must-fail-with
229
230 ! This url is misparsed bu request-url can fix it
231 { T{ url
232    { protocol "http" }
233    { host "www.google.com" }
234    { path "/" }
235    { port 80 }
236 } } [ "www.google.com" request-url ] unit-test
237
238 ! This one is not fixable, leave it as it is
239 { T{ url } } [ "" request-url ] unit-test