]> gitweb.factorcode.org Git - factor.git/blob - basis/http/server/requests/requests-tests.factor
http.server.requests: refactor the http.server vocabs request handling into its own...
[factor.git] / basis / http / server / requests / requests-tests.factor
1 USING: accessors assocs http http.server.requests io.streams.string kernel
2 sequences tools.test urls ;
3 IN: http.server.requests.tests
4
5 ! content-length in combination with POST
6 { "foo=bar" "7" } [
7     {
8         "POST / HTTP/1.1"
9         "connection: close"
10         "host: 127.0.0.1:55532"
11         "user-agent: Factor http.client"
12         "content-length: 7"
13         ""
14         "foo=bar"
15     } "\n" join [ read-request ] with-string-reader
16     [ post-data>> data>> ] [ header>> "content-length" of ] bi
17 ] unit-test
18
19 { f "0" } [
20     {
21         "POST / HTTP/1.1"
22         "connection: close"
23         "host: 127.0.0.1:55532"
24         "user-agent: Factor http.client"
25         "content-length: 0"
26         ""
27         ""
28     } "\n" join [ read-request ] with-string-reader
29     [ post-data>> data>> ] [ header>> "content-length" of ] bi
30 ] unit-test
31
32 ! RFC 2616: Section 4.1
33 ! In the interest of robustness, servers SHOULD ignore any empty
34 ! line(s) received where a Request-Line is expected. In other words, if
35 ! the server is reading the protocol stream at the beginning of a
36 ! message and receives a CRLF first, it should ignore the CRLF.
37 [
38     T{ request
39         { method "GET" }
40         { url URL" /" }
41         { version "1.0" }
42         { header H{ } }
43         { cookies V{ } }
44         { redirects 10 }
45     }
46 ] [
47     "\r\n\r\n\r\nGET / HTTP/1.0\r\n\r\n"
48     [ read-request ] with-string-reader
49 ] unit-test
50
51 ! RFC 2616: Section 19.3
52 ! The line terminator for message-header fields is the sequence CRLF.
53 ! However, we recommend that applications, when parsing such headers,
54 ! recognize a single LF as a line terminator and ignore the leading CR.
55 [ t ] [
56     {
57         "GET / HTTP/1.1"
58         "connection: close"
59         "host: 127.0.0.1:55532"
60         "user-agent: Factor http.client"
61     } [ "\n" join ] [ "\r\n" join ] bi
62     [ [ read-request ] with-string-reader ] same?
63 ] unit-test