]> gitweb.factorcode.org Git - factor.git/blob - basis/http/server/responses/responses.factor
9bade222ff40ed03e79b4eb8cc482cf49d9a08eb
[factor.git] / basis / http / server / responses / responses.factor
1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: math.parser http accessors kernel xml.syntax xml.writer
4 io io.streams.string io.encodings.utf8 ;
5 IN: http.server.responses
6
7 : <content> ( body content-type -- response )
8     <response>
9         200 >>code
10         "Document follows" >>message
11         utf8 >>content-encoding
12         swap >>content-type
13         swap >>body ;
14
15 : <text-content> ( body -- response )
16     "text/plain" <content> ;
17
18 : <html-content> ( body -- response )
19     "text/html" <content> ;
20
21 : trivial-response-body ( code message -- )
22     <XML
23         <html>
24             <body>
25                 <h1><-> <-></h1>
26             </body>
27         </html>
28     XML> write-xml ;
29
30 : <trivial-response> ( code message -- response )
31     2dup [ trivial-response-body ] with-string-writer
32     <html-content>
33         swap >>message
34         swap >>code ;
35
36 : <304> ( -- response )
37     304 "Not modified" <trivial-response> ;
38
39 : <403> ( -- response )
40     403 "Forbidden" <trivial-response> ;
41
42 : <400> ( -- response )
43     400 "Bad request" <trivial-response> ;
44
45 : <404> ( -- response )
46     404 "Not found" <trivial-response> ;