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