1 USING: assocs continuations help.markup help.syntax http http.server.requests
2 io.servers kernel math strings urls vocabs.refresh ;
3 USE: html.forms ! needed for $link in param
6 HELP: trivial-responder
7 { $class-description "The class of trivial responders, which output the same response for every request. New instances are created by calling " { $link <trivial-responder> } "." } ;
9 HELP: <trivial-responder>
10 { $values { "response" response } { "trivial-responder" trivial-responder } }
11 { $description "Creates a new trivial responder which outputs the same response for every request." } ;
14 { $var-description "If set to a true value, the HTTP server will log the time taken to process each request." } ;
18 { "path" "a sequence of strings" } { "responder" "a responder" }
19 { "response" response } }
20 { $description "Calls a responder." } ;
24 { "path" "a sequence of strings" } { "responder" "a responder" }
25 { "response" response } }
26 { $contract "Processes an HTTP request and returns a response." }
27 { $notes "When this word is called, various dynamic variables are set; see " { $link "http.server.requests" } "." } ;
30 { $var-description "If set to a true value, the HTTP server will call " { $link refresh-all } " on each request, and error pages will contain stack traces." } ;
33 { $var-description "The responder which will handle HTTP requests." } ;
36 { $values { "?" boolean } }
37 { $description "Outputs if the current request is a POST request.s" } ;
39 HELP: responder-nesting
40 { $description "A sequence of " { $snippet "{ path responder }" } " pairs." } ;
42 HELP: handle-client-error
43 { $values { "error" error } }
44 { $description "Handles an error that may have occurred during the processing of a request. The rules are: 1) if the error is caused by an empty request line, it is silenced because it is a redundant dummy request issued by certain browsers. 2) if the error is a " { $link request-error } " then it is logged and the client is served a 400 Bad Request. 3) all other errors are thrown upwards." } ;
47 { $class-description "The class of HTTP servers. New instances are created by calling " { $link <http-server> } "." } ;
50 { $values { "server" http-server } }
51 { $description "Creates a new HTTP server with default parameters." } ;
54 { $values { "port" integer } { "http-server" http-server } }
55 { $description "Starts an HTTP server on the specified port number." }
56 { $notes "For more flexibility, use " { $link <http-server> } " and fill in the tuple slots before calling " { $link start-server } "." } ;
59 { $description "Starts a thread which rotates the logs and e-mails a summary of HTTP requests every 24 hours. See " { $link "logging.insomniac" } "." } ;
62 { $values { "request" request } { "assoc" assoc } }
63 { $description "Outputs the query parameters (if the current request is a GET or HEAD request) or the POST parameters (if the current request is a POST request)." } ;
70 { $description "Outputs the value of a query parameter (if the current request is a GET or HEAD request) or a POST parameter (if the current request is a POST request)." }
71 { $notes "Instead of using this word, it is better to use " { $vocab-link "furnace.actions" } " and the associated validation machinery, which allows you to access values using " { $link "html.forms.values" } " words." } ;
74 { $var-description "A variable holding an assoc of query parameters (if the current request is a GET or HEAD request) or POST parameters (if the current request is a POST request)." }
75 { $notes "Instead of using this word, it is better to use " { $vocab-link "furnace.actions" } " and the associated validation machinery, which allows you to access values using " { $link "html.forms.values" } " words." } ;
77 ARTICLE: "http.server.requests" "HTTP request variables"
78 "The following variables are set by the HTTP server at the beginning of a request. Responder implementations may access these variables."
92 "Additional variables may be set by vocabularies such as " { $vocab-link "html.forms" } " and " { $vocab-link "furnace.sessions" } "." ;
94 ARTICLE: "http.server.responders" "HTTP server responders"
95 "Responders process requests and output " { $link "http.responses" } ". To implement a responder, define a new class and implement a method on the following generic word:"
96 { $subsections call-responder* }
97 "The HTTP server dispatches requests to a main responder:"
98 { $subsections main-responder }
99 "The main responder may in turn dispatch it a subordinate dispatcher, and so on. To call a subordinate responder, use the following word:"
100 { $subsections call-responder }
101 "A simple implementation of a responder which always outputs the same response:"
106 "Writing new responders by hand is rarely necessary, because in most cases it is easier to use " { $vocab-link "furnace.actions" } " instead."
107 { $vocab-subsection "Furnace actions" "furnace.actions" } ;
109 ARTICLE: "http.server.variables" "HTTP server variables"
110 "The following global variables control the behavior of the HTTP server. Both are off by default."
116 ARTICLE: "http.server" "HTTP server"
117 "The " { $vocab-link "http.server" } " vocabulary implements an HTTP and HTTPS server on top of " { $vocab-link "io.servers" } "."
119 "http.server.responders"
120 "http.server.requests"
122 "Various types of responders are defined in other vocabularies:"
124 "http.server.dispatchers"
125 "http.server.filters"
127 "Useful canned responses:"
129 "http.server.responses"
130 "http.server.redirection"
134 "http.server.variables"
135 "http.server.remapping"
142 "The " { $vocab-link "furnace" } " framework implements high-level abstractions which make developing web applications much easier than writing responders by hand." ;