]> gitweb.factorcode.org Git - factor.git/blob - extra/http/server/responses/responses.factor
4056f0c7f00d1d7494aedb0506bd7279158fb5e7
[factor.git] / extra / http / server / responses / responses.factor
1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: html.elements math.parser http accessors kernel
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-charset
12         swap >>content-type
13         swap >>body ;
14     
15 : trivial-response-body ( code message -- )
16     <html>
17         <body>
18             <h1> [ number>string write bl ] [ write ] bi* </h1>
19         </body>
20     </html> ;
21
22 : <trivial-response> ( code message -- response )
23     2dup [ trivial-response-body ] with-string-writer
24     "text/html" <content>
25         swap >>message
26         swap >>code ;
27
28 : <304> ( -- response )
29     304 "Not modified" <trivial-response> ;
30
31 : <403> ( -- response )
32     403 "Forbidden" <trivial-response> ;
33
34 : <400> ( -- response )
35     400 "Bad request" <trivial-response> ;
36
37 : <404> ( -- response )
38     404 "Not found" <trivial-response> ;