]> gitweb.factorcode.org Git - factor.git/blob - basis/http/client/client-tests.factor
vm: fix arm files
[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 {
7     T{ request
8         { url T{ url { protocol "http" } { host "www.apple.com" } { port 80 } { path "/index.html" } } }
9         { proxy-url T{ url } }
10         { method "GET" }
11         { version "1.1" }
12         { cookies V{ } }
13         { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
14         { redirects 10 }
15     }
16 } [
17     "http://www.apple.com/index.html"
18     <get-request>
19 ] unit-test
20
21 {
22     T{ request
23         { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
24         { proxy-url T{ url } }
25         { method "GET" }
26         { version "1.1" }
27         { cookies V{ } }
28         { header H{ { "Connection" "close" } { "User-Agent" "Factor http.client" } } }
29         { redirects 10 }
30     }
31 } [
32     "https://www.amazon.com/index.html"
33     <get-request>
34 ] unit-test
35
36 { "HEAD" } [ "http://google.com" <head-request> method>> ] unit-test
37 { "DELETE" } [ "http://arc.com" <delete-request> method>> ] unit-test
38 { "TRACE" } [ "http://concatenative.org" <trace-request> method>> ] unit-test
39 { "OPTIONS" } [ "http://factorcode.org" <options-request> method>> ] unit-test
40
41 ! Do not re-enable this for the test suite.
42 ! We should replace this with a similar test that does not
43 ! hit the velox.ch website.
44 ! { t } [
45     ! "https://alice.sni.velox.ch" http-get nip
46     ! [ "Great!" subseq-of? ]
47     ! [ "TLS SNI Test Site: alice.sni.velox.ch" subseq-of? ] bi and
48 ! ] unit-test
49
50 { t } [
51     {
52         "HTTP/1.1 200 Document follows"
53         "connection: close"
54         "content-type: text/html; charset=UTF-8"
55         "date: Wed, 12 Oct 2011 18:57:49 GMT"
56         "server: Factor http.server"
57     } [ join-lines ] [ "\r\n" join ] bi
58     [ [ read-response ] with-string-reader ] same?
59 ] unit-test
60
61 { "www.google.com:8080" } [
62     URL" http://foo:bar@www.google.com:8080/foo?bar=baz#quux" authority-uri
63 ] unit-test
64
65 { "/index.html?bar=baz" } [
66     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
67     <get-request>
68         f >>proxy-url
69     request-uri
70 ] unit-test
71
72 { "/index.html?bar=baz" } [
73     "https://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 { "http://www.apple.com/index.html?bar=baz" } [
80     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
81     <get-request>
82         "http://localhost:3128" >>proxy-url
83     request-uri
84 ] unit-test
85
86 { "www.apple.com:80" } [
87     "http://user:pass@www.apple.com/index.html?bar=baz#foo"
88     "CONNECT" <client-request>
89         f >>proxy-url
90     request-uri
91 ] unit-test
92
93 { "www.apple.com:443" } [
94     "https://www.apple.com/index.html"
95     "CONNECT" <client-request>
96         f >>proxy-url
97     request-uri
98 ] unit-test
99
100 { f } [
101     "" "no_proxy" [
102         "www.google.fr" <get-request> no-proxy?
103     ] with-variable
104 ] unit-test
105
106 { f } [
107     "," "no_proxy" [
108         "www.google.fr" <get-request> no-proxy?
109     ] with-variable
110 ] unit-test
111
112 { f } [
113     "foo,,bar" "no_proxy" [
114         "www.google.fr" <get-request> no-proxy?
115     ] with-variable
116 ] unit-test
117
118 { t } [
119     "foo,www.google.fr,bar" "no_proxy" [
120         "www.google.fr" <get-request> no-proxy?
121     ] with-variable
122 ] unit-test
123
124 ! TODO support 192.168.0.16/4 ?
125 CONSTANT: classic-proxy-settings H{
126     { "http.proxy" "http://proxy.private:3128" }
127     { "https.proxy" "http://proxysec.private:3128" }
128     { "no_proxy" "localhost,127.0.0.1,.allprivate,.a.subprivate,b.subprivate" }
129 }
130
131 { f } [
132     classic-proxy-settings [
133        "localhost" "GET" <client-request> ?default-proxy proxy-url>>
134     ] with-variables
135 ] unit-test
136
137 { f } [
138     classic-proxy-settings [
139        "127.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
140     ] with-variables
141 ] unit-test
142
143 { URL" http://proxy.private:3128" } [
144     classic-proxy-settings [
145        "27.0.0.1" "GET" <client-request> ?default-proxy proxy-url>>
146     ] with-variables
147 ] unit-test
148
149 { f } [
150     classic-proxy-settings [
151        "foo.allprivate" "GET" <client-request> ?default-proxy proxy-url>>
152     ] with-variables
153 ] unit-test
154
155 { f } [
156     classic-proxy-settings [
157        "bar.a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
158     ] with-variables
159 ] unit-test
160
161 { URL" http://proxy.private:3128" } [
162     classic-proxy-settings [
163        "a.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
164     ] with-variables
165 ] unit-test
166
167 { f } [
168     classic-proxy-settings [
169        "bar.b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
170     ] with-variables
171 ] unit-test
172
173 { f } [
174     classic-proxy-settings [
175        "b.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
176     ] with-variables
177 ] unit-test
178
179 { URL" http://proxy.private:3128" } [
180     classic-proxy-settings [
181        "bara.subprivate" "GET" <client-request> ?default-proxy proxy-url>>
182     ] with-variables
183 ] unit-test
184
185 { URL" http://proxy.private:3128" } [
186     classic-proxy-settings [
187        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
188     ] with-variables
189 ] unit-test
190
191 { URL" //localhost:3128" } [
192     { { "http.proxy" "//localhost:3128" } } [
193        "google.com" "GET" <client-request> ?default-proxy proxy-url>>
194     ] with-variables
195 ] unit-test
196
197 { URL" //localhost:3128" } [
198     "google.com" "GET" <client-request>
199     URL" //localhost:3128" >>proxy-url ?default-proxy proxy-url>>
200 ] unit-test
201
202 { URL" //localhost:3128" } [
203     "google.com" "GET" <client-request>
204     "//localhost:3128" >>proxy-url ?default-proxy proxy-url>>
205 ] unit-test
206
207 { URL" http://proxysec.private:3128" } [
208     classic-proxy-settings [
209        "https://google.com" "GET" <client-request> ?default-proxy proxy-url>>
210     ] with-variables
211 ] unit-test
212
213 { URL" http://proxy.private:3128" } [
214     classic-proxy-settings [
215        "allprivate.google.com" "GET" <client-request> ?default-proxy proxy-url>>
216     ] with-variables
217 ] unit-test
218
219 [
220     <url> 3128 >>port "http.proxy" [
221        "http://www.google.com" "GET" <client-request> ?default-proxy
222     ] with-variable
223 ] [ invalid-proxy? ] must-fail-with
224
225 ! This url is misparsed bu request-url can fix it
226 { T{ url
227     { protocol "http" }
228     { host "www.google.com" }
229     { path "/" }
230     { port 80 }
231 } } [ "www.google.com" request-url ] unit-test
232
233 ! This one is not fixable, leave it as it is
234 { T{ url } } [ "" request-url ] unit-test