]> gitweb.factorcode.org Git - factor.git/blob - basis/http/client/client-tests.factor
0b2120d31abbeb6f8e45e213222ebcb6af0bf818
[factor.git] / basis / http / client / client-tests.factor
1 USING: accessors 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         { method "GET" }
17         { version "1.1" }
18         { cookies V{ } }
19         { header H{ { "connection" "close" } { "user-agent" "Factor http.client" } } }
20         { redirects 10 }
21     }
22 ] [
23     "http://www.apple.com/index.html"
24     <get-request>
25 ] unit-test
26
27 [
28     T{ request
29         { url T{ url { protocol "https" } { host "www.amazon.com" } { port 443 } { path "/index.html" } } }
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 [ t ] [
47     {
48         "HTTP/1.1 200 Document follows"
49         "connection: close"
50         "content-type: text/html; charset=UTF-8"
51         "date: Wed, 12 Oct 2011 18:57:49 GMT"
52         "server: Factor http.server"
53     } [ "\n" join ] [ "\r\n" join ] bi
54     [ [ read-response ] with-string-reader ] bi@ =
55 ] unit-test