fix acceptor-remove-session
[hunchentoot.git] / doc / index.xml
blob06fe3de24b40437da51cd07973fedd5d2ab98fe6
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="clixdoc.xsl" ?>
4 <clix:documentation xmlns='http://www.w3.org/1999/xhtml' xmlns:clix='http://bknr.net/clixdoc'>
5   <clix:title>HUNCHENTOOT - The Common Lisp web server formerly known as TBNL</clix:title>
6   <clix:short-description>
7     A full-featured web server written in Common Lisp offering things
8     like HTTP/1.1 chunking, persistent connections, and SSL.  Includes
9     a framework for building dynamic websites interactively.
10   </clix:short-description>
12   <h2>
13     <a href="http://www.htg1.de/hunchentoot/hunchentoot.html"
14        title="Click here for the Hunchentoot logo"
15        class="noborder">
16       <img align="top" width="93" height="45" border="0" src="hunchentoot.gif" />
17     </a>
18     HUNCHENTOOT - The Common Lisp web server formerly known as TBNL
19   </h2>
21   <blockquote>
22     <clix:chapter name='abstract' title='Abstract'>
23       <p>
24         Hunchentoot is a web server written in Common Lisp and at the
25         same time a toolkit for building dynamic websites.  As a
26         stand-alone web server, Hunchentoot is capable of HTTP/1.1
27         chunking (both directions), persistent connections
28         (keep-alive), and SSL.
29       </p>
30       <p>
31         Hunchentoot provides facilities like automatic session
32         handling (with and without cookies), logging, customizable
33         error handling, and easy access to GET and POST parameters
34         sent by the client. It does <em>not</em> include functionality
35         to programmatically generate HTML output. For this task you
36         can use any library you like, e.g. (shameless self-plug)
37         <a href="http://weitz.de/cl-who/">CL-WHO</a> or
38         <a href="http://weitz.de/html-template/">HTML-TEMPLATE</a>.
39       </p>
40       <p>
41         Hunchentoot talks with its front-end or with the client over
42         TCP/IP sockets and optionally uses multiprocessing to handle
43         several requests at the same time.  Therefore, it cannot be
44         implemented completely in
45         <a href="http://www.lispworks.com/documentation/HyperSpec/Front/index.htm">portable
46         Common Lisp</a>.  It currently works "natively" with
47         <a href="http://www.lispworks.com/">LispWorks</a> (which is the
48         main development and testing platform), and additionally on all
49         Lisps which are supported by the compatibility
50         layers <a href="http://common-lisp.net/project/usocket/">usocket</a>
51         and <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux
52         Threads</a>.
53       </p>
54       <p>
55         Hunchentoot comes with a
56         <a href="http://www.opensource.org/licenses/bsd-license.php">BSD-style
57         license</a> so you can basically do with it whatever you want.
58       </p>
59       <p>
60         Hunchentoot is (or was) for example used by
61         <a href="http://quickhoney.com/">QuickHoney</a>,
62         <a href="http://postabon.com/">Postabon</a>,
63         <a href="http://www.city-farming.de/">City Farming</a>,
64         <a href="http://www.thoughtcrime.us/tp/">Trip Planner</a>,
65         <a href="http://www.jalat.com/">Jalat</a>,
66         <a href="http://heikestephan.de/">Heike Stephan</a>,
67         <a href="http://www.memetrics.com/">xOs</a>, and
68         <a href="http://syseng.nist.gov/moss">the</a>
69         <a href="http://syseng.nist.gov/se-interop">NIST</a>.
70       </p>
71       <p>
72         <font color="red">Download shortcut:</font>
73         <a href="http://weitz.de/files/hunchentoot.tar.gz">http://weitz.de/files/hunchentoot.tar.gz</a>.
74       </p>
75     </clix:chapter>
76   </blockquote>
78   <clix:chapter name='contents' title='Contents'></clix:chapter>
79   <clix:contents></clix:contents>
81   <clix:chapter name="install" title="Download and installation">
82     Hunchentoot depends on a couple of other Lisp libraries which you'll need
83     to install first:
84     <ul>
85       <li>Pierre R. Mai's <a href="http://www.cliki.net/md5">MD5</a>,</li>
86       <li>Kevin Rosenberg's <a href="http://www.cliki.net/cl-base64">CL-BASE64</a>,</li>
87       <li>Janis Dzerins' <a href="http://common-lisp.net/project/rfc2388/">RFC2388</a>,</li>
88       <li>Peter Seibel's <a href="http://weitz.de/cl-fad/">CL-FAD</a>,</li>
89       <li>Gary King's <a href="http://common-lisp.net/project/trivial-backtrace/">trivial-backtrace</a>,</li>
90       <li>Erik Huelsmann's <a href="http://common-lisp.net/project/usocket">usocket</a> (unless you're using LispWorks),</li>
91       <li>Greg Pfeil's <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux Threads</a> (unless you're using LispWorks),
92       </li>
93       <li>
94         David Lichteblau's <a href="http://common-lisp.net/project/cl-plus-ssl/">CL+SSL</a>
95         (unless you're using LispWorks),
96       </li>
97       <li>
98         and my own <a href="http://weitz.de/flexi-streams/">FLEXI-STREAMS</a> (0.12.0 or higher),
99         <a href="http://weitz.de/chunga/">Chunga</a> (1.0.0 or
100         higher), and <a href="http://weitz.de/cl-ppcre/">
101         CL-PPCRE</a> (plus
102         <a href="http://weitz.de/cl-who/">CL-WHO</a> for the <a href="#start">example code</a>
103         and <a href="http://weitz.de/drakma/">Drakma</a> for the <a href="#testing">tests</a>).
104       </li>
105     </ul>
107     Make sure to use the <em>newest</em> versions of all of these
108     libraries (which might themselves depend on other libraries) - try
109     the repository versions if you're in doubt.  Note: You can compile
110     Hunchentoot without SSL support - and thus without the need to
111     have CL+SSL - if you add <code>:HUNCHENTOOT-NO-SSL</code> to
112     <a href="http://www.lispworks.com/documentation/HyperSpec/Body/v_featur.htm">
113       <code>*FEATURES*</code></a> <em>before</em> you compile it.
114     <p>
115       Hunchentoot will only work with Lisps where
116       the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#character_code">character
117       codes</a> of
118       all <a href="http://en.wikipedia.org/wiki/ISO_8859-1">Latin-1</a>
119       characters coincide with their
120       Unicode <a href="http://en.wikipedia.org/wiki/Code_point">code
121       points</a> (which is the case for all current implementations I
122       know).
123     </p>
124     <p>
125       Hunchentoot itself together with this documentation can be
126       downloaded from
127       <a href="http://weitz.de/files/hunchentoot.tar.gz">http://weitz.de/files/hunchentoot.tar.gz</a>.
128       The current version is <clix:library-version/>.
129     </p>
130     <p>
131       The preferred method to compile and load Hunchentoot is via <a
132       href="http://www.cliki.net/asdf">ASDF</a>.  If you want to avoid
133       downloading and installing all the dependencies manually, give
134       Zach Beane's excellent <a
135       href="http://www.quicklisp.org/">Quicklisp</a> system a try.
136     </p>
137     <p>
138       Hunchentoot and its dependencies can also be installed with <a
139       href="http://common-lisp.net/project/asdf-install/">ASDF-INSTALL</a>,
140       <a href="http://common-lisp.net/project/clbuild/">clbuild</a>,
141       or my own <a href="http://weitz.de/starter-pack/">Starter
142       Pack</a>.  There's also a port for <a
143       href="http://www.gentoo.org/proj/en/lisp/common-lisp/index.xml">Gentoo
144       Linux</a> thanks to Matthew Kennedy.
145     </p>
146     <p>
147       The current development version of Hunchentoot can be found
148       at <a href="https://github.com/edicl/hunchentoot">https://github.com/edicl/hunchentoot</a>.
149       If you want to send patches, please fork the github repository and send pull requests.
150     </p>
151     <p>
152       Luís Oliveira maintains an
153       unofficial <a href="http://darcs.net/">darcs</a> repository of
154       Hunchentoot at
155       <a href="http://common-lisp.net/~loliveira/ediware/">http://common-lisp.net/~loliveira/ediware/</a>.
156     </p>
158     <clix:subchapter name="port80" title="Running Hunchentoot on port 80">
160       Hunchentoot does not come with code to help with running it on a
161       privileged port (i.e. port 80 or 443) on Unix-like operating
162       systems.  Modern Unix-like systems have specific, non-portable
163       ways to allow non-root users to listen to privileged ports, so
164       including such functionality in Hunchentoot was considered
165       unnecessary.  Please refer to online resources for help.  At the
166       time of this writing, the YAWS documentation has a <a
167       href="http://yaws.hyber.org/privbind.yaws">comprehensive
168       writeup</a> on the topic.
169     </clix:subchapter>
171     <clix:subchapter name="proxy" title="Hunchentoot behind a proxy">
173       If you're feeling unsecure about exposing Hunchentoot to the wild,
174       wild Internet or if your Lisp web application is part of a larger
175       website, you can hide it behind a
176       <a href="http://en.wikipedia.org/wiki/Proxy_server">proxy server</a>.
177       One approach that I have used several times is to employ Apache's
178       <a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html">mod_proxy</a>
179       module with a configuration that looks like this:
181 <pre><a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypass" class="noborder">ProxyPass</a> /hunchentoot http://127.0.0.1:3000/hunchentoot
182 <a href="http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypassreverse" class="noborder">ProxyPassReverse</a> /hunchentoot http://127.0.0.1:3000/hunchentoot</pre>
184       This will tunnel all requests where the URI path begins with
185       <code>"/hunchentoot"</code> to a (Hunchentoot) server listening on
186       port 3000 on the same machine.
188       <p>
189         Of course, there are
190         <a href="http://www.red-bean.com/pipermail/lispweb/2006-October/001342.html">several
191           other</a> (more lightweight) web proxies that you could use
192         instead of Apache.
193       </p>
194     </clix:subchapter>
195   </clix:chapter>
197   <clix:chapter name="mail" title="Support and mailing lists">
199     For questions, bug reports, feature requests, improvements, or
200     patches please use the
201     <a href="http://common-lisp.net/mailman/listinfo/tbnl-devel">tbnl-devel
202       mailing list</a>. If you want to be notified about future
203       releases subscribe to the
204     <a href="http://common-lisp.net/mailman/listinfo/tbnl-announce">tbnl-announce
205       mailing list</a>. These mailing lists were made available thanks
206     to the services of
207     <a href="http://common-lisp.net/">common-lisp.net</a>.  You can
208     <b>search</b> the devel mailing list
209     <a href="http://google.com/coop/cse?cx=002927904911724867201%3A0l5rif_cxj0">here</a>
210     (thanks to Tiarnán Ó Corráin).
211     <p>
212       If you want to send patches, please
213       <a href="http://weitz.de/patches.html">read this first</a>.
214     </p>
215   </clix:chapter>
217   <clix:chapter name="start" title="Your own webserver (the easy teen-age New York version)">
218     Starting your own web server is pretty easy.  Do something like this:
219 <pre>(hunchentoot:<a class="noborder" href="#start">start</a> (make-instance 'hunchentoot:<a class="noborder" href="#acceptor">easy-acceptor</a> :port 4242))</pre>
220     That's it.  Now you should be able to enter the address
221     "<a href='http://127.0.0.1:4242/'><code>http://127.0.0.1:4242/</code></a>" in
222     your browser and see something, albeit nothing very interesting
223     for now.
225     <p>
226       By default, Hunchentoot serves the files from the
227       <code><i>www/</i></code> directory in its source tree.  In the
228       distribution, that directory contains a HTML version of the
229       documentation as well as the error templates.  The location of
230       the document root directory can be specified when creating a new
231       <clix:ref>ACCEPTOR</clix:ref> instance by the way of the
232       <clix:ref>ACCEPTOR-DOCUMENT-ROOT</clix:ref>.  Likewise, the
233       location of the error template directory can be specified by the
234       <clix:ref>ACCEPTOR-ERROR-TEMPLATE-DIRECTORY</clix:ref>.
235     </p>
237     <p>
238       The <clix:ref>EASY-ACCEPTOR</clix:ref> class implements a
239       framework for developing web applications.  Handlers are defined
240       using the <clix:ref>DEFINE-EASY-HANDLER</clix:ref> macro.
241       Request dispatching is performed according to the list of
242       dispatch functions in <clix:ref>*DISPATCH-TABLE*</clix:ref>.
243       Each of the functions on that list is called to determine
244       whether it wants to handle the request, provided as single
245       argument.  If a dispatcher function wants to handle the request,
246       it returns another function to actually create the desired page.
247     </p>
249     <p>
250       <clix:ref>DEFINE-EASY-HANDLER</clix:ref> is accompanied by a set
251       of dispatcher creation functions that can be used to create
252       dispatchers for standard tasks.  These are documented in the <a
253       class="noborder" href="#easy-handlers">subchapter on easy
254       handlers</a>
255     </p>
257     <p>
258       Now be a bit more adventurous, try this
259 <pre>(hunchentoot:<a class="noborder" href="#define-easy-handler">define-easy-handler</a> (say-yo :uri "/yo") (name)
260   (setf (hunchentoot:<a class="noborder" href="#content-type*">content-type*</a>) "text/plain")
261   (format nil "Hey~@[ ~A~]!" name))</pre>
262       and see what happens at "<a href='http://127.0.0.1:4242/yo'><code>http://127.0.0.1:4242/yo</code></a>" or
263       "<a href='http://127.0.0.1:4242/yo?name=Dude'><code>http://127.0.0.1:4242/yo?name=Dude</code></a>" .
264     </p>
266     <p>
267     Hunchentoot comes with a little example website which you can use
268     to see if it works and which should also demonstrate a couple of
269     the things you can do with Hunchentoot.  To start the example
270     website, enter the following code into your listener:
272 <pre>(<a class="noborder" href="http://common-lisp.net/~mmommer/asdf-howto.shtml#sec11">asdf:oos</a> 'asdf:load-op :hunchentoot-test)</pre>
274     Now go to "<a href='http://127.0.0.1:4242/hunchentoot/test'><code>http://127.0.0.1:4242/hunchentoot/test</code></a>" and play a bit.
275     </p>
276   </clix:chapter>
278   <clix:chapter name="tutorials" title="Tutorials and add-ons">
279     <p>
280       Here are some Hunchentoot tutorials done by others:
281     </p>
282     <ul>
283       <li>
284         <a href="http://www.adampetersen.se/articles/lispweb.htm">"Lisp for the Web"</a> by Adam Petersen.
285       </li>
286       <li>
287         Two <a href="http://myblog.rsynnott.com/2007/09/getting-started-with-hunchento.html">getting</a>
288         <a href="http://myblog.rsynnott.com/2007/10/doing-more-with-hunchentoot-cl-server.html">started</a>
289         articles by Robert Synnott.
290       </li>
291       <li>
292         <a href="http://newartisans.com/2007/11/running-common-lisp-behind-apache/">Running Common Lisp
293           behind Apache</a> by John Wiegley.  (And there's a
294         <a href="http://newartisans.com/2007/11/a-quick-hunchentoot-primer/">second part</a>.)
295       </li>
296       <li>
297         A <a href="http://www.lispcast.com/index.php/2007/10/lispcast-writing-a-simple-reddit-clone-in-common-lisp/">"LispCast"</a>
298         by Eric Normand about writing a <a href="http://reddit.com/">Reddit</a> clone using
299         Hunchentoot.  Apparently the first part of a
300         <a href="http://bc.tech.coop/blog/071028.html">series</a>.
301       </li>
302       <li>
303         A <a href="http://roeim.net/vetle/docs/cl-webapp-intro/">tutorial</a> about
304         implementing a blog in Common Lisp by Vetle Roeim.
305       </li>
306       <li>
307         A <a href="http://www.jalat.com/blogs/lisp?id=3">tutorial</a> for (an older version of)
308         Hunchentoot by Asbjørn Bjørnstad.
309       </li>
310       <li>
311         A <a href="http://www.frank-buss.de/lisp/tbnl.html">TBNL tutorial</a> from Frank Buss.
312         (Hunchentoot is not <a href="http://weitz.de/tbnl/">TBNL</a>, but the two are similar enough
313         to make the tutorial worthwhile.)
314       </li>
315       <li>
316         For Win32, Bill
317         Clementson <a href="http://bc.tech.coop/blog/041105.html">explains</a>
318         how to set up Hunchentoot's
319         predecessor <a href="http://weitz.de/tbnl/">TBNL</a> with
320         Apache/mod_lisp.  See
321         also <a href="http://bc.tech.coop/blog/061013.html">http://bc.tech.coop/blog/061013.html</a>.
322       </li>
323     </ul>
325     Check the dates of these tutorials!  Many of them might not be a
326     perfect fit with the latest release of Hunchentoot as there have
327     been several changes to its API recently, especially in 2009.
328     Also, the fact that these tutorials are listed here doesn't
329     necessarily mean that I endorse them or think that they show
330     idiomatic Lisp code.  You'll have to decide yourself if they're
331     helpful to you or not.
333     <p>
334       Here is some software which extends Hunchentoot or is based on it:
335     </p>
336     <ul>
337       <li>Tomo Matsumoto's web application
338       framework <a href="http://web4r.org/en/">web4r</a>.
339       </li>
340       <li>
341         <a href="http://common-lisp.net/project/cl-weblocks/">Weblocks</a>
342         by Slava Akhmechet is a "continuations-based web framework" which is
343         based on Hunchentoot.
344       </li>
345       <li>
346         <a href="http://common-lisp.net/project/ht-ajax/ht-ajax.html">HT-AJAX</a> is
347         an <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">Ajax</a>
348         framework for Hunchentoot by Ury Marshak.
349       </li>
350       <li>
351         <a
352         href="http://martin-loetzsch.de/ht-simple-ajax/">HT-SIMPLE-AJAX</a>
353         is a simplified version of HT-AJAX.
354       </li>
355       <li>
356         Mac Chan
357         <a href="http://common-lisp.net/pipermail/tbnl-devel/2007-May/001324.html">has
358           ported <a href="http://lemonodor.com/">John Wiseman</a>'s
359           <a href="http://www.lemonodor.com/archives/000128.html">Lisp
360             Server Pages</a> to Hunchentoot.</a>
361       </li>
362       <li>
363         <a href="http://site.znain.com/dl/lisp/hunchentoot-dir-lister/">hunchentoot-dir-lister</a>
364         is a directory listing addition for Hunchentoot by Dimitre Liotev.
365       </li>
366       <li>
367         Cyrus Harmon's
368         <a href="http://cyrusharmon.org/blog/display?id=64">nuclblog</a> is a
369         <a href="http://en.wikipedia.org/wiki/Blog">blog</a> engine which uses Hunchentoot.
370       </li>
371       <li>
372         <a href="http://cyrusharmon.org/projects?project=hunchentoot-cgi">hunchentoot-cgi</a>
373         (also by Cyrus Harmon) provides
374         <a href="http://en.wikipedia.org/wiki/Common_Gateway_Interface">CGI</a>
375         handlers for Hunchentoot.
376       </li>
377       <li>
378         <a href="http://weitz.de/cl-webdav/">CL-WEBDAV</a> is a <a href="http://webdav.org/">WebDAV</a>
379         server based on Hunchentoot.
380       </li>
381       <li>
382         <a href="http://restas.lisper.ru/">RESTAS</a> is a web
383         framework based on Hunchentoot.
384       </li>
385     </ul>
386   </clix:chapter>
388   <clix:chapter name="reference" title="Function and variable reference">
390     <clix:subchapter name="acceptors" title="Acceptors">
392       If you want Hunchentoot to actually do something, you have to create and
393       <a href="#start">start</a> an <a href="#acceptor">acceptor</a>.
394       You can also run several acceptors in one image, each one
395       listening on a different different port.
397       <clix:class name='acceptor'>
398         <clix:description>
399           To create a Hunchentoot webserver, you make an instance of
400           this class or one of its subclasses and use the generic
401           function <clix:ref>START</clix:ref> to start it (and
402           <clix:ref>STOP</clix:ref> to stop it).  Use the
403           <code>:port</code> initarg if you don&#039;t want to listen
404           on the default http port 80.  There are other initargs most
405           of which you probably won&#039;t need very often.  They are
406           explained in detail in the docstrings of the slot
407           definitions for this class.
408           <p>
409             Unless you are in a Lisp without MP capabilities, you can
410             have several active instances of
411             <clix:ref>ACCEPTOR</clix:ref> (listening on different
412             ports) at the same time.
413           </p>
414         </clix:description>
415       </clix:class>
417       <clix:class name='ssl-acceptor'>
418         <clix:description>Create and <clix:ref>START</clix:ref> an instance of this class
419         (instead of <clix:ref>ACCEPTOR</clix:ref>) if you want an https server.  There are two
420         required initargs, <code>:SSL-CERTIFICATE-FILE</code> and <code>:SSL-PRIVATEKEY-FILE</code>, for
421         pathname designators denoting the certificate file and the key file in
422         PEM format.  On LispWorks, you can have both in one file in which case
423         the second initarg is optional.  You can also use the
424         <code>:SSL-PRIVATEKEY-PASSWORD</code> initarg to provide a password
425         (as a string) for the key file (or <code>NIL</code>, the default, for
426         no password).
427         <p>
428           The default port for <clix:ref>SSL-ACCEPTOR</clix:ref> instances is 443 instead of 80
429         </p>
430         </clix:description>
431       </clix:class>
433       <clix:function generic='true' name='start'>
434         <clix:lambda-list>acceptor
435         </clix:lambda-list>
436         <clix:returns>acceptor
437         </clix:returns>
438         <clix:description>Starts <clix:arg>acceptor</clix:arg> so that it begins accepting
439         connections.  Returns the acceptor.
440         </clix:description>
441       </clix:function>
443       <clix:function generic='true' name='stop'>
444         <clix:lambda-list>acceptor &amp;key soft</clix:lambda-list>
445         <clix:returns>acceptor
446         </clix:returns>
447         <clix:description>Stops the <clix:arg>acceptor</clix:arg> so
448         that it no longer accepts requests.  If
449         <clix:arg>soft</clix:arg> is true, and there are any requests
450         in progress, wait until all requests are fully processed, but
451         meanwhile do not accept new requests.  Note that
452         <clix:arg>soft</clix:arg> must not be set when calling
453         <clix:ref>stop</clix:ref> from within a request handler, as
454         that will deadlock.
455         </clix:description>
456       </clix:function>
458       <clix:special-variable name='*acceptor*'>
459         <clix:description>The current ACCEPTOR object in the context of a request.
460         </clix:description>
461       </clix:special-variable>
463       <clix:function generic='true' name='acceptor-listen-backlog'>
464         <clix:lambda-list>listen-backlog
465         </clix:lambda-list>
466         <clix:returns>number-of-pending-connections
467         </clix:returns>
468         <clix:description>
469           Number of pending connections allowed in the listen socket
470           before the kernel rejects further incoming connections.
471           Non-LispWorks only.
472         </clix:description>
473       </clix:function>
475       <clix:readers generic='true'>
476         <clix:listed-reader generic='true' name='acceptor-address'>
477           <clix:lambda-list>acceptor
478           </clix:lambda-list>
479           <clix:returns>address
480           </clix:returns>
481         </clix:listed-reader>
483         <clix:listed-reader generic='true' name='acceptor-port'>
484           <clix:lambda-list>acceptor
485           </clix:lambda-list>
486           <clix:returns>port
487           </clix:returns>
488         </clix:listed-reader>
490         <clix:listed-reader generic='true' name='acceptor-read-timeout'>
491           <clix:lambda-list>acceptor
492           </clix:lambda-list>
493           <clix:returns>read-timeout
494           </clix:returns>
495         </clix:listed-reader>
497         <clix:listed-reader generic='true' name='acceptor-ssl-certificate-file'>
498           <clix:lambda-list>ssl-acceptor
499           </clix:lambda-list>
500           <clix:returns>ssl-certificate-file
501           </clix:returns>
502         </clix:listed-reader>
504         <clix:listed-reader generic='true' name='acceptor-ssl-privatekey-file'>
505           <clix:lambda-list>ssl-acceptor
506           </clix:lambda-list>
507           <clix:returns>ssl-privatekey-file
508           </clix:returns>
509         </clix:listed-reader>
511         <clix:listed-reader generic='true' name='acceptor-ssl-privatekey-password'>
512           <clix:lambda-list>ssl-acceptor
513           </clix:lambda-list>
514           <clix:returns>ssl-privatekey-password
515           </clix:returns>
516         </clix:listed-reader>
518         <clix:listed-reader generic='true' name='acceptor-write-timeout'>
519           <clix:lambda-list>acceptor
520           </clix:lambda-list>
521           <clix:returns>write-timeout
522           </clix:returns>
523         </clix:listed-reader>
525         <clix:description>
526           These are readers for various slots of <clix:ref>ACCEPTOR</clix:ref>
527           objects (and some of them obviously only make sense
528           for <clix:ref>SSL-ACCEPTOR</clix:ref> objects).  See the docstrings of
529           these slots for more information and note that there are corresponding
530           initargs for all of them.
531         </clix:description>
532       </clix:readers>
534       <clix:accessors generic='true'>
535         <clix:listed-accessor generic='true' name='acceptor-access-log-destination'>
536           <clix:lambda-list>acceptor
537           </clix:lambda-list>
538           <clix:returns>(or pathname null)
539           </clix:returns>
540         </clix:listed-accessor>
542         <clix:listed-accessor generic='true' name='acceptor-document-root'>
543           <clix:lambda-list>acceptor
544           </clix:lambda-list>
545           <clix:returns>(or pathname null)
546           </clix:returns>
547         </clix:listed-accessor>
549         <clix:listed-accessor generic='true' name='acceptor-error-template-directory'>
550           <clix:lambda-list>acceptor
551           </clix:lambda-list>
552           <clix:returns>(or pathname null)
553           </clix:returns>
554         </clix:listed-accessor>
556         <clix:listed-accessor generic='true' name='acceptor-input-chunking-p'>
557           <clix:lambda-list>acceptor
558           </clix:lambda-list>
559           <clix:returns>input-chunking-p
560           </clix:returns>
561         </clix:listed-accessor>
563         <clix:listed-accessor generic='true' name='acceptor-message-log-destination'>
564           <clix:lambda-list>acceptor
565           </clix:lambda-list>
566           <clix:returns>(or pathname null)
567           </clix:returns>
568         </clix:listed-accessor>
570         <clix:listed-accessor generic='true' name='acceptor-name'>
571           <clix:lambda-list>acceptor
572           </clix:lambda-list>
573           <clix:returns>name
574           </clix:returns>
575         </clix:listed-accessor>
577         <clix:listed-accessor generic='true' name='acceptor-output-chunking-p'>
578           <clix:lambda-list>acceptor
579           </clix:lambda-list>
580           <clix:returns>output-chunking-p
581           </clix:returns>
582         </clix:listed-accessor>
584         <clix:listed-accessor generic='true' name='acceptor-persistent-connections-p'>
585           <clix:lambda-list>acceptor
586           </clix:lambda-list>
587           <clix:returns>persistent-connections-p
588           </clix:returns>
589         </clix:listed-accessor>
591         <clix:listed-accessor generic='true' name='acceptor-reply-class'>
592           <clix:lambda-list>acceptor
593           </clix:lambda-list>
594           <clix:returns>reply-class
595           </clix:returns>
596         </clix:listed-accessor>
598         <clix:listed-accessor generic='true' name='acceptor-request-class'>
599           <clix:lambda-list>acceptor
600           </clix:lambda-list>
601           <clix:returns>request-class
602           </clix:returns>
603         </clix:listed-accessor>
605         <clix:description>
606           These are accessors for various slots of <clix:ref>ACCEPTOR</clix:ref>
607           objects.  See the docstrings of these slots for more information and
608           note that there are corresponding initargs for all of them.
609         </clix:description>
610       </clix:accessors>
612       <clix:function generic='true' name='acceptor-ssl-p'>
613         <clix:lambda-list>acceptor
614         </clix:lambda-list>
615         <clix:returns>generalized-boolean
616         </clix:returns>
617         <clix:description>Returns a true value if <clix:arg>acceptor</clix:arg> uses SSL
618         connections.  The default is to unconditionally return <code>NIL</code> and
619         subclasses of <clix:ref>ACCEPTOR</clix:ref> must specialize this method to signal that
620         they&#039;re using secure connections - see the <clix:ref>SSL-ACCEPTOR</clix:ref> class.
621         </clix:description>
622       </clix:function>
624       <clix:special-variable name='*default-connection-timeout*'>
625         <clix:description>The default connection timeout used when an
626         acceptor is reading from and writing to a socket stream.  Note that
627         some Lisps allow you to set different timeouts for reading and writing
628         and you can specify both values via initargs when you create
629         an <a href="#acceptors">acceptor</a>.
630         </clix:description>
631       </clix:special-variable>
633       <clix:function generic='true' name='acceptor-remove-session'>
634         <clix:lambda-list>acceptor session
635         </clix:lambda-list>
636         <clix:returns>|
637         </clix:returns>
638         <clix:description>
639           This function is called whenever a session in
640           <clix:ref>ACCEPTOR</clix:ref> is being destroyed because of
641           a session timout or an explicit
642           <clix:ref>REMOVE-SESSION</clix:ref> call.
643         </clix:description>
644       </clix:function>
646     </clix:subchapter>
648     <clix:subchapter name="acceptor-behaviour" title="Customizing acceptor behaviour">
650       If you want to modify what acceptors do, you should subclass
651       <clix:ref>ACCEPTOR</clix:ref> (or <clix:ref>SSL-ACCEPTOR</clix:ref>) and
652       specialize the generic functions that constitute their behaviour (see
653       example below).  The life of an acceptor looks like this: It is started
654       with the function <clix:ref>START</clix:ref> which immediately calls
655       <clix:ref>START-LISTENING</clix:ref> and then applies the function
656       <clix:ref>EXECUTE-ACCEPTOR</clix:ref> to its <a
657       href="#taskmasters">taskmaster</a>.  This function will eventually call
658       <clix:ref>ACCEPT-CONNECTIONS</clix:ref> which is responsible for setting
659       things up to wait for clients to connect.  For each incoming connection
660       which comes in, <clix:ref>HANDLE-INCOMING-CONNECTION</clix:ref> is applied
661       to the taskmaster which will either call
662       <clix:ref>PROCESS-CONNECTION</clix:ref> directly, or will create a thread
663       to call it.  <clix:ref>PROCESS-CONNECTION</clix:ref> calls
664       <clix:ref>INITIALIZE-CONNECTION-STREAM</clix:ref> before it does anything
665       else, then it selects and calls a function which handles the <a
666       href="#requests">request</a>, and finally it sends the <a
667       href="#replies">reply</a> to the client before it calls
668       <clix:ref>RESET-CONNECTION-STREAM</clix:ref>.  If the connection is
669       persistent, this procedure is repeated (except for the intialization step)
670       in a loop until the connection is closed.  The acceptor is stopped with
671       <clix:ref>STOP</clix:ref>.
673       <p>
674         If you just want to use the standard acceptors that come with
675         Hunchentoot, you don't need to know anything about the functions
676         listed in this section.
677       </p>
679       <clix:function generic='true' name='start-listening'>
680         <clix:lambda-list>acceptor
681         </clix:lambda-list>
682         <clix:returns>|
683         </clix:returns>
684         <clix:description>Sets up a listen socket for the given acceptor and
685         enables it to listen to incoming connections.  This function is called
686         from the thread that starts the acceptor initially and may return
687         errors resulting from the listening operation (like &#039;address in use&#039;
688         or similar).
689         </clix:description>
690       </clix:function>
692       <clix:function generic='true' name='accept-connections'>
693         <clix:lambda-list>acceptor
694         </clix:lambda-list>
695         <clix:returns>nil
696         </clix:returns>
697         <clix:description>In a loop, accepts a connection and hands it over
698         to the acceptor's taskmaster for processing using
699         <clix:ref>HANDLE-INCOMING-CONNECTION</clix:ref>. On LispWorks, this
700         function returns immediately, on other Lisps it returns only once the
701         acceptor has been stopped.
702         </clix:description>
703       </clix:function>
705       <clix:function generic='true' name='process-connection'>
706         <clix:lambda-list>acceptor socket
707         </clix:lambda-list>
708         <clix:returns>nil
709         </clix:returns>
710         <clix:description>
711           This function is called by the taskmaster when a new client
712           connection has been established.  Its arguments are the
713           <clix:ref>ACCEPTOR</clix:ref> object and a LispWorks socket
714           handle or a usocket socket stream object in
715           <clix:arg>socket</clix:arg>.  It reads the request headers,
716           sets up the <a href="#requests">request</a> and <a
717           href="#replies">reply</a> objects, and hands over to
718           <clix:ref>PROCESS-REQUEST</clix:ref> which calls
719           <clix:ref>HANDLE-REQUEST</clix:ref> to select and call a
720           handler for the request and sends its reply to the client.
721           This is done in a loop until the stream has to be closed or
722           until a connection timeout occurs.  It is probably not a
723           good idea to re-implement this method until you really,
724           really know what you're doing.
725         </clix:description>
726       </clix:function>
728       <clix:function generic='true' name='initialize-connection-stream'>
729         <clix:lambda-list>acceptor stream
730         </clix:lambda-list>
731         <clix:returns>stream
732         </clix:returns>
733         <clix:description>
734           Can be used to modify the stream which is used to
735           communicate between client and server before the request is
736           read.  The default method of <clix:ref>ACCEPTOR</clix:ref>
737           does nothing, but see for example the method defined for
738           <clix:ref>SSL-ACCEPTOR</clix:ref>.  All methods of this
739           generic function <em>must</em> return the stream to use.
740         </clix:description>
741       </clix:function>
743       <clix:function generic='true' name='reset-connection-stream'>
744         <clix:lambda-list>acceptor stream
745         </clix:lambda-list>
746         <clix:returns>stream
747         </clix:returns>
748         <clix:description>
749           Resets the stream which is used to communicate
750           between client and server after one request has been served so that it
751           can be used to process the next request.  This generic function is
752           called after a request has been processed and <em>must</em> return the
753           stream.
754         </clix:description>
755       </clix:function>
757       <clix:function name="acceptor-log-access" generic="true">
758         <clix:lambda-list>acceptor &amp;key return-code</clix:lambda-list>
759         <clix:description>
760           Function to call to log access to the acceptor.  The
761           <clix:arg>return-code</clix:arg> keyword argument contains additional
762           information about the request to log.  In addition, it can use the
763           standard request and reply accessor functions that are available to
764           handler functions to find out more information about the request.
765         </clix:description>
766       </clix:function>
768       <clix:function name="acceptor-log-message" generic="true">
769         <clix:lambda-list>acceptor log-level format-string &amp;rest format-arguments</clix:lambda-list>
770         <clix:description>
771           Function to call to log messages by the <clix:arg>acceptor</clix:arg>.  It must accept
772           a severity level for the message, which will be one of :ERROR, :INFO,
773           or :WARNING, a format string and an arbitary number of formatting
774           arguments.
775         </clix:description>
776       </clix:function>
778       <clix:function name="acceptor-status-message" generic="true">
779         <clix:lambda-list>acceptor http-return-code &amp;key &amp;allow-other-keys</clix:lambda-list>
780         <clix:description>
781           This function is called when a request's handler has been
782           called but failed to provide content to send back to the
783           client.  It converts the
784           <clix:arg>HTTP-STATUS-CODE</clix:arg> to some request
785           contents, typically a human readable description of the
786           status code to be displayed to the user.
788           If an ERROR-TEMPLATE-DIRECTORY is set in the current
789           acceptor and the directory contains a file corresponding to
790           HTTP-STATUS-CODE named &lt;code&gt;.html, that file is sent
791           to the client after variable substitution.  Variables are
792           referenced by ${&lt;variable-name&gt;}.
794           Additional keyword arguments may be provided which are made
795           available to the templating logic as substitution variables.
796           These variables can be interpolated into error message
797           templates in, which contains the current URL relative to the
798           server and without GET parameters.
800           In addition to the variables corresponding to keyword
801           arguments, the script-name, lisp-implementation-type,
802           lisp-implementation-version and hunchentoot-version
803           variables are available.
804         </clix:description>
805       </clix:function>
806     </clix:subchapter>
808   <clix:subchapter name="subclassing-acceptors"
809                    title="An example of how to subclass ACCEPTOR">
811     This example shows how to subclass <clix:ref>ACCEPTOR</clix:ref> in order to
812     provide Hunchentoot with basic virtual host support.&#x00A0; It assumes
813     Hunchentoot is sitting behind an Internet-facing reverse-proxy web server
814     that maps the host (or domain) part of incoming HTTP requests to unique
815     localhost ports.
817     <pre>(asdf:load-system "hunchentoot")
818 (asdf:load-system "drakma")
820 ;;; Subclass ACCEPTOR
821 (defclass vhost (tbnl:acceptor)
822   ;; slots
823   ((dispatch-table
824     :initform '()
825     :accessor dispatch-table
826     :documentation "List of dispatch functions"))
827   ;; options
828   (:default-initargs                    ; default-initargs must be used
829    :address "127.0.0.1"))               ; because ACCEPTOR uses it
831 ;;; Specialise ACCEPTOR-DISPATCH-REQUEST for VHOSTs
832 (defmethod tbnl:acceptor-dispatch-request ((vhost vhost) request)
833   ;; try REQUEST on each dispatcher in turn
834   (mapc (lambda (dispatcher)
835           (let ((handler (funcall dispatcher request)))
836             (when handler               ; Handler found. FUNCALL it and return result
837               (return-from tbnl:acceptor-dispatch-request (funcall handler)))))
838         (dispatch-table vhost))
839   (call-next-method))
841 ;;; ======================================================================
842 ;;; Now all we need to do is test it
844 ;;; Instantiate VHOSTs
845 (defvar vhost1 (make-instance 'vhost :port 50001))
846 (defvar vhost2 (make-instance 'vhost :port 50002))
848 ;;; Populate each dispatch table
849 (push
850  (tbnl:create-prefix-dispatcher "/foo" 'foo1)
851  (dispatch-table vhost1))
852 (push
853  (tbnl:create-prefix-dispatcher "/foo" 'foo2)
854  (dispatch-table vhost2))
856 ;;; Define handlers
857 (defun foo1 () "Hello")
858 (defun foo2 () "Goodbye")
860 ;;; Start VHOSTs
861 (tbnl:start vhost1)
862 (tbnl:start vhost2)
864 ;;; Make some requests
865 (drakma:http-request "http://127.0.0.1:50001/foo")
866 ;;; =|
867 ;;; 127.0.0.1 - [2012-06-08 14:30:39] "GET /foo HTTP/1.1" 200 5 "-" "Drakma/1.2.6 (SBCL 1.0.56; Linux; 2.6.32-5-686; http://weitz.de/drakma/)"
868 ;;; =>
869 ;;; "Hello"
870 ;;; 200
871 ;;; ((:CONTENT-LENGTH . "5") (:DATE . "Fri, 08 Jun 2012 14:30:39 GMT")
872 ;;;  (:SERVER . "Hunchentoot 1.2.3") (:CONNECTION . "Close")
873 ;;;  (:CONTENT-TYPE . "text/html; charset=utf-8"))
874 ;;; #&lt;PURI:URI http://127.0.0.1:50001/foo&gt;
875 ;;; #&lt;FLEXI-STREAMS:FLEXI-IO-STREAM {CA90059}&gt;
876 ;;; T
877 ;;; "OK"
878 (drakma:http-request "http://127.0.0.1:50002/foo")
879 ;;; =|
880 ;;; 127.0.0.1 - [2012-06-08 14:30:47] "GET /foo HTTP/1.1" 200 7 "-" "Drakma/1.2.6 (SBCL 1.0.56; Linux; 2.6.32-5-686; http://weitz.de/drakma/)"
881 ;;; =&gt;
882 ;;; "Goodbye"
883 ;;; 200
884 ;;; ((:CONTENT-LENGTH . "7") (:DATE . "Fri, 08 Jun 2012 14:30:47 GMT")
885 ;;;  (:SERVER . "Hunchentoot 1.2.3") (:CONNECTION . "Close")
886 ;;;  (:CONTENT-TYPE . "text/html; charset=utf-8"))
887 ;;; #&lt;PURI:URI http://127.0.0.1:50002/foo&gt;
888 ;;; #&lt;FLEXI-STREAMS:FLEXI-IO-STREAM {CAE8059}&gt;
889 ;;; T
890 ;;; "OK"</pre>
892     How to make each VHOST write to separate access log streams (or files) is
893     left as an exercise to the reader.
895   </clix:subchapter>
897     <clix:subchapter name="taskmasters" title="Taskmasters">
898       As a "normal" Hunchentoot user, you can completely ignore
899       taskmasters and skip this section.  But if you're still reading,
900       here are the dirty details: Each <a
901       href="#acceptors">acceptor</a> has a taskmaster associated with
902       it at creation time.  It is the taskmaster's job to distribute
903       the work of accepting and handling incoming connections.  The
904       acceptor calls the taskmaster if appropriate and the taskmaster
905       calls back into the acceptor.  This is done using the generic
906       functions described in this and the <a
907       href="#acceptor-behaviour">previous</a> section.  Hunchentoot
908       comes with two standard taskmaster implementations - one (which
909       is the default used on multi-threaded Lisps) which starts a new
910       thread for each incoming connection and one which handles all
911       requests sequentially.  It should for example be relatively
912       straightforward to create a taskmaster which allocates threads
913       from a fixed pool instead of creating a new one for each
914       connection.
916       <p>
917         You can control the resources consumed by a threaded taskmaster via
918         two initargs. <code>:max-thread-count</code> lets you set the maximum
919         number of request threads that can be processes simultaneously.  If
920         this is <code>nil</code>, the is no thread limit imposed.
922         <code>:max-accept-count</code> lets you set the maximum number of requests
923         that can be outstanding (i.e. being processed or queued for processing).
925         If <code>:max-thread-count</code> is supplied and <code>:max-accept-count</code>
926         is <code>NIL</code>, then a <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>
927         error will be generated if there are more than the max-thread-count
928         threads processing requests.  If both <code>:max-thread-count</code>
929         and <code>:max-accept-count</code> are supplied, then max-thread-count
930         must be less than max-accept-count; if more than max-thread-count
931         requests are being processed, then requests up to max-accept-count
932         will be queued until a thread becomes available.  If more than
933         max-accept-count requests are outstanding, then a <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>
934         error will be generated.
936         In a load-balanced environment with multiple Hunchentoot servers, it's
937         reasonable to provide <code>:max-thread-count</code> but leave
938         <code>:max-accept-count</code> null.   This will immediately result
939         in <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref> when one server is
940         out of resources, so the load balancer can try to find another server.
942         In an environment with a single Hunchentoot server, it's reasonable
943         to provide both <code>:max-thread-count</code> and a somewhat larger value
944         for <code>:max-accept-count</code>.  This will cause a server that's almost
945         out of resources to wait a bit; if the server is completely out of resources,
946         then the reply will be <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>.
947         The default for these values is 100 and 120, respectively.
948       </p>
950       <p>
951         If you want to implement your own taskmasters, you should subclass
952         <clix:ref>TASKMASTER</clix:ref> or one of its subclasses,
953         <clix:ref>SINGLE-THREADED-TASKMASTER</clix:ref> or
954         <clix:ref>ONE-THREAD-PER-CONNECTION-TASKMASTER</clix:ref>, and
955         specialize the generic functions in this section.
956       </p>
958       <clix:class name='taskmaster'>
959         <clix:description>
960           An instance of this class is responsible for distributing
961           the work of handling requests for its acceptor.  This is an
962           "abstract" class in the sense that usually only instances of
963           subclasses of <clix:ref>TASKMASTER</clix:ref> will be used.
964         </clix:description>
965       </clix:class>
967       <clix:class name='one-thread-per-connection-taskmaster'>
968         <clix:description>
969           A taskmaster that starts one thread for listening to
970           incoming requests and one thread for each incoming
971           connection.
972           <p>
973             This is the default taskmaster implementation for multi-threaded Lisp
974             implementations.
975           </p>
976         </clix:description>
977       </clix:class>
979       <clix:class name='single-threaded-taskmaster'>
980         <clix:description>
981           A taskmaster that runs synchronously in the
982           thread where the <clix:ref>START</clix:ref> function was invoked (or
983           in the case of LispWorks in the thread started
984           by <a href="http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-61.htm#marker-910861"><code>COMM:START-UP-SERVER</code></a>).
985           This is the simplest possible taskmaster implementation in that its
986           methods do nothing but calling their acceptor &quot;sister&quot;
987           methods - <clix:ref>EXECUTE-ACCEPTOR</clix:ref> calls <clix:ref>ACCEPT-CONNECTIONS</clix:ref>,
988           <clix:ref>HANDLE-INCOMING-CONNECTION</clix:ref> calls <clix:ref>PROCESS-CONNECTION</clix:ref>.
989         </clix:description>
990       </clix:class>
992       <clix:class name='multi-threaded-taskmaster'>
993         <clix:description>
994           This is an abstract class for taskmasters that use multiple threads;
995           it is not a concrete class and you should not instantiate it with
996           <code>MAKE-INSTANCE</code>.
997           Instead, you should instantiate its subclass
998           <clix:ref>ONE-THREAD-PER-CONNECTION-TASKMASTER</clix:ref> described above.
999           <clix:ref>MULTI-THREADED-TASKMASTER</clix:ref>
1000           is intended to be inherited from by extensions to Hunchentoot,
1001           such as <a href="http://common-lisp.net/project/qitab/">quux-hunchentoot</a>'s
1002           <code>THREAD-POOLING-TASKMASTER</code>,
1003           though at the moment, doing so only inherits one slot and one method,
1004           on <clix:ref>EXECUTE-ACCEPTOR</clix:ref>,
1005           to have it start a new thread for the acceptor,
1006           then saved in said slot.
1007         </clix:description>
1008       </clix:class>
1010       <clix:function generic='true' name='execute-acceptor'>
1011         <clix:lambda-list>taskmaster
1012         </clix:lambda-list>
1013         <clix:returns>result
1014         </clix:returns>
1015         <clix:description>This is a callback called by the acceptor once it
1016         has performed all initial processing to start listening for incoming
1017         connections (see <clix:ref>START-LISTENING</clix:ref>).  It usually calls the
1018         <clix:ref>ACCEPT-CONNECTIONS</clix:ref> method of the acceptor, but depending on the
1019         taskmaster instance the method might be called from a new thread.
1020         </clix:description>
1021       </clix:function>
1023       <clix:function generic='true' name='handle-incoming-connection'>
1024         <clix:lambda-list>taskmaster socket
1025         </clix:lambda-list>
1026         <clix:returns>result
1027         </clix:returns>
1028         <clix:description>
1029           This function is called by the acceptor to start
1030           processing of requests on a new incoming connection.  <clix:arg>socket</clix:arg> is the
1031           usocket instance that represents the new connection (or a socket
1032           handle on LispWorks).  The taskmaster starts processing requests on
1033           the incoming connection by calling the <clix:ref>PROCESS-CONNECTION</clix:ref>
1034           method of the acceptor instance.  The <clix:arg>socket</clix:arg> argument is passed to
1035           <clix:ref>PROCESS-CONNECTION</clix:ref> as an argument.
1037           If the taskmaster is a multi-threaded taskmaster, <clix:ref>HANDLE-INCOMING-THREAD</clix:ref>
1038           will call <clix:ref>CREATE-REQUEST-HANDLER-THREAD</clix:ref>, which will call
1039           <clix:ref>PROCESS-CONNECTION</clix:ref> in a new thread.
1040           <clix:ref>HANDLE-INCOMING-THREAD</clix:ref> might issue a
1041           <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref> error
1042           if there are too many request threads or it might block waiting for a
1043           request thread to finish.
1044               </clix:description>
1045             </clix:function>
1047             <clix:function generic='true' name='start-thread'>
1048             <clix:lambda-list>taskmaster thunk &amp;key
1049             </clix:lambda-list>
1050             <clix:returns>thread
1051             </clix:returns>
1052               <clix:description>This function is a callback that
1053                 starts a new thread that will call the given <clix:arg>thunk</clix:arg>
1054                 in the context of the proper <clix:arg>taskmaster</clix:arg>,
1055                 with appropriate context-dependent keyword arguments.
1056                 <clix:ref>ONE-THREAD-PER-CONNECTION-TASKMASTER</clix:ref> uses it in
1057                 <clix:ref>EXECUTE-ACCEPTOR</clix:ref>
1058                 and <clix:ref>CREATE-REQUEST-HANDLER-THREAD</clix:ref>,
1059                 but specialized taskmasters may define more functions that use it.
1060                 By default, it just creates a thread calling the thunk
1061                 with a specified <clix:arg>name</clix:arg> keyword argument.
1062                 Specialized taskmasters may wrap special bindings and condition handlers
1063                 around the thunk call, register the thread in a management table, etc.
1064               </clix:description>
1065             </clix:function>
1067             <clix:function generic='true' name='create-request-handler-thread'>
1068             <clix:lambda-list>taskmaster socket
1069             </clix:lambda-list>
1070             <clix:returns>thread
1071             </clix:returns>
1072               <clix:description>This function is called by <clix:ref>HANDLE-INCOMING-THREAD</clix:ref>
1073           to create a new thread which calls <clix:ref>PROCESS-CONNECTION</clix:ref>.
1074           If you specialize this function, you must be careful to have the thread
1075           call <clix:ref>DECREMENT-TASKMASTER-REQUEST-COUNT</clix:ref> before
1076           it exits.  A typical method will look like this:
1078                 <pre>(defmethod create-request-handler-thread ((taskmaster monitor-taskmaster) socket)
1079   (bt:make-thread
1080    (lambda ()
1081      (with-monitor-error-handlers
1082          (unwind-protect
1083               (with-monitor-variable-bindings
1084                   (process-connection (taskmaster-acceptor taskmaster) socket))
1085            (decrement-taskmaster-request-count taskmaster))))))</pre>
1093         </clix:description>
1094       </clix:function>
1096       <clix:function generic='true' name='shutdown'>
1097         <clix:lambda-list>taskmaster
1098         </clix:lambda-list>
1099         <clix:returns>taskmaster
1100         </clix:returns>
1101         <clix:description>Shuts down the taskmaster, i.e. frees all resources
1102         that were set up by it.  For example, a multi-threaded taskmaster
1103         might terminate all threads that are currently associated with it.
1104         This function is called by the acceptor's <clix:ref>STOP</clix:ref> method.
1105         </clix:description>
1106       </clix:function>
1108       <clix:accessor generic='true' name='taskmaster-acceptor'>
1109         <clix:lambda-list>taskmaster
1110         </clix:lambda-list>
1111         <clix:returns>acceptor
1112         </clix:returns>
1113         <clix:description>
1114           This is an accessor for the slot of a <clix:ref>TASKMASTER</clix:ref>
1115           object that links back to the <a href="#acceptors">acceptor</a> it is
1116           associated with.
1117         </clix:description>
1118       </clix:accessor>
1120     </clix:subchapter>
1122     <clix:subchapter name="request-dispatch" title="Request dispatch and handling">
1124       The main job of <clix:ref>HANDLE-REQUEST</clix:ref> is to select
1125       and call a function which handles the request, i.e. which looks
1126       at the data the client has sent and prepares an appropriate
1127       reply to send back.  This is by default implemented as follows:
1128       <p>
1129         The ACCEPTOR class defines a
1130         <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> generic
1131         function which is used to actually dispatch the request.  This
1132         function is called by the default method of
1133         <clix:ref>HANDLE-REQUEST</clix:ref>.  Each
1134         <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> method looks at
1135         the request object and depending on its contents decides to
1136         either handle the request or call the next method.
1137       </p>
1138       <p>
1139         In order to dispatch a request, Hunchentoot calls the
1140         <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> generic
1141         functions.  The method for <clix:ref>ACCEPTOR</clix:ref> tries
1142         to serve a static file relative to it's
1143         <clix:ref>ACCEPTOR-DOCUMENT-ROOT</clix:ref>.  Application
1144         specific acceptor subclasses will typically perform URL
1145         parsing and dispatching according to the policy that is
1146         required.
1147       </p>
1148       <p>
1149         The default method of <clix:ref>HANDLE-REQUEST</clix:ref> sets
1150         up <a href="#logging">standard logging and error handling</a>
1151         before it calls the acceptor's request dispatcher.
1152       </p>
1153       <p>
1154         Request handlers do their work by modifying
1155         the <a href="#replies">reply object</a> if necessary and by eventually
1156         returning the response body in the form of a string or a binary
1157         sequence.  As an alternative, they can also
1158         call <clix:ref>SEND-HEADERS</clix:ref> and write directly to a stream.
1159       </p>
1160     </clix:subchapter>
1162     <clix:subchapter name="easy-handlers" title="Using the easy-handler framework">
1163       <p>
1164         The <clix:ref>EASY-ACCEPTOR</clix:ref> class defines a method
1165         for <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> that walks
1166         through the list <clix:ref>*DISPATCH-TABLE*</clix:ref> which
1167         consists of <em>dispatch functions</em>.  Each of these
1168         functions accepts the request object as its only argument and
1169         either returns a request handler to handle the request or
1170         <code>NIL</code> which means that the next dispatcher in the
1171         list will be tried.  If all dispatch functions return
1172         <code>NIL</code>, the next
1173         <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> will be called.
1174       </p>
1175       <p>
1176         All functions and variables in this section are related to the
1177         easy request dispatch mechanism and are meaningless if you're
1178         using your own request dispatcher.
1179       </p>
1181       <clix:class name='easy-acceptor'>
1182         <clix:description>
1183           This class defines no additional slots with respect to
1184           <clix:ref>ACCEPTOR</clix:ref>.  It only serves as an
1185           additional type for dispatching calls to
1186           <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref>.  In order to
1187           use the easy handler framework, acceptors of this class or
1188           one of its subclasses must be used.
1189         </clix:description>
1190       </clix:class>
1192       <clix:class name='easy-ssl-acceptor'>
1193         <clix:description>
1194           This class mixes the <clix:ref>SSL-ACCEPTOR</clix:ref> and
1195           the <clix:ref>EASY-ACCEPTOR</clix:ref> classes.  It is used
1196           when both ssl and the easy handler framework are required.
1197         </clix:description>
1198       </clix:class>
1200       <clix:special-variable name='*dispatch-table*'>
1201         <clix:description>
1202           A global list of dispatch functions.  The initial value is a
1203           list consisting of the symbol
1204           <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>.
1205         </clix:description>
1206       </clix:special-variable>
1208       <clix:function name="create-prefix-dispatcher">
1209         <clix:lambda-list>prefix handler</clix:lambda-list>
1210         <clix:returns>dispatch-fn</clix:returns>
1211         <clix:description>
1212           A convenience function which will return a dispatcher that
1213           returns <clix:arg>handler</clix:arg> whenever the path part of
1214           the request URI starts with the
1215           string <clix:arg>prefix</clix:arg>.
1216         </clix:description>
1217       </clix:function>
1219       <clix:function name="create-regex-dispatcher">
1220         <clix:lambda-list>regex handler</clix:lambda-list>
1221         <clix:returns>dispatch-fn</clix:returns>
1222         <clix:description>
1223           A convenience function which will return a dispatcher that
1224           returns <clix:arg>handler</clix:arg> whenever the path part of
1225           the request URI matches
1226           the <a href="http://weitz.de/cl-ppcre/">CL-PPCRE</a> regular
1227           expression <clix:arg>regex</clix:arg> (which can be a string, an
1228           s-expression, or a scanner).
1229         </clix:description>
1230       </clix:function>
1232       <clix:function name="create-folder-dispatcher-and-handler">
1233         <clix:lambda-list>uri-prefix base-path <clix:lkw>optional</clix:lkw> content-type</clix:lambda-list>
1234         <clix:returns>dispatch-fn</clix:returns>
1235         <clix:description>
1236           Creates and returns a dispatch function which will dispatch to
1237           a handler function which emits the file relative
1238           to <clix:arg>base-path</clix:arg> that is denoted by the URI of
1239           the request relative
1240           to <clix:arg>uri-prefix</clix:arg>.  <clix:arg>uri-prefix</clix:arg>
1241           must be a string ending with a
1242           slash, <clix:arg>base-path</clix:arg> must be a pathname
1243           designator for an existing directory.
1244           Uses <clix:ref>HANDLE-STATIC-FILE</clix:ref> internally.
1245           <p>
1246             If <clix:arg>content-type</clix:arg> is <em>not</em>
1247             <code>NIL</code>, it will be used as a the content type for
1248             all files in the folder.  Otherwise (which is the default)
1249             the content type of each file will be
1250             determined <a href="#handle-static-file">as usual</a>.
1251           </p>
1252         </clix:description>
1253       </clix:function>
1255       <clix:function name='create-static-file-dispatcher-and-handler'>
1256         <clix:lambda-list>uri path
1257         <clix:lkw>optional
1258         </clix:lkw> content-type
1259         </clix:lambda-list>
1260         <clix:returns>result
1261         </clix:returns>
1262         <clix:description>
1263           Creates and returns a request dispatch function which will
1264           dispatch to a handler function which emits the file denoted
1265           by the pathname designator PATH with content type
1266           CONTENT-TYPE if the SCRIPT-NAME of the request matches the
1267           string URI.  If CONTENT-TYPE is NIL, tries to determine the
1268           content type via the file&#039;s suffix.
1269         </clix:description>
1270       </clix:function>
1272       <clix:function macro="true" name="define-easy-handler">
1273         <clix:lambda-list>description lambda-list [[declaration* | documentation]] form*</clix:lambda-list>
1274         <clix:description>
1275           Defines a handler as if
1276           by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_defun.htm">
1277             <code>DEFUN</code></a> and optionally registers it with a
1278           URI so that it will be found
1279           by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>.
1280           <p>
1281             <clix:arg>description</clix:arg> is either a
1282             symbol <clix:arg>name</clix:arg> or a list matching the
1283             <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_de.htm">destructuring
1284               lambda list</a>
1285           </p>
1286           <pre>(name &amp;key uri acceptor-names default-parameter-type default-request-type).</pre>
1287           <clix:arg>lambda-list</clix:arg> is a list the elements of which
1288           are either a symbol <clix:arg>var</clix:arg> or a list matching
1289           the destructuring lambda list
1290           <pre>(var &amp;key real-name parameter-type init-form request-type).</pre>
1291           The resulting handler will be a Lisp function with the
1292           name <clix:arg>name</clix:arg> and keyword parameters named by
1293           the <clix:arg>var</clix:arg> symbols.
1294           Each <clix:arg>var</clix:arg> will be bound to the value of the
1295           GET or POST parameter called <clix:arg>real-name</clix:arg> (a
1296           string) before the body of the function is executed.
1297           If <clix:arg>real-name</clix:arg> is not provided, it will be
1298           computed
1299           by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stg_up.htm#string-downcase">downcasing</a>
1300           the symbol name of <clix:arg>var</clix:arg>.
1301           <p>
1302             If <clix:arg>uri</clix:arg> (which is evaluated) is provided,
1303             then it must be a string or
1304             a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_designator">function
1305               designator</a> for a unary function.  In this case, the
1306             handler will be returned
1307             by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>,
1308             if <clix:arg>uri</clix:arg> is a string and
1309             the <a href="#script-name">script name</a> of the current
1310             request is <clix:arg>uri</clix:arg>, or
1311             if <clix:arg>uri</clix:arg> designates a function and applying
1312             this function to
1313             the <a href="#*request*">current <code>REQUEST</code>
1314               object</a> returns a true value.
1315           </p>
1316           <p>
1317             <clix:arg>acceptor-names</clix:arg> (which is evaluated) can be a
1318             list of symbols which means that the handler will only be
1319             returned by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref> in
1320             acceptors which have one of these names
1321             (see <clix:ref>ACCEPTOR-NAME</clix:ref>).  <clix:arg>acceptor-names</clix:arg> can also be the
1322             symbol <code>T</code> which means that the handler will be
1323             returned by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>
1324             in <em>every</em> acceptor.
1325           </p>
1326           <p>
1327             Whether the GET or POST parameter (or both) will be taken into
1328             consideration, depends on <clix:arg>request-type</clix:arg>
1329             which can
1330             be <code>:GET</code>, <code>:POST</code>, <code>:BOTH</code>,
1331             or <code>NIL</code>.  In the last case, the value of
1332             <clix:arg>default-request-type</clix:arg> (the default of which
1333             is <code>:BOTH</code>) will be used.
1334           </p>
1335           <p>
1336             The value of <clix:arg>var</clix:arg> will usually be a string
1337             (unless it resulted from a <a href="#upload">file upload</a>
1338             in which case it won't be converted at all), but
1339             if <clix:arg>parameter-type</clix:arg> (which is evaluated) is
1340             provided, the string will be converted to another Lisp type by
1341             the following rules:
1342           </p>
1343           <p>
1344             If the corresponding GET or POST parameter wasn't provided by
1345             the client, <clix:arg>var</clix:arg>'s value will
1346             be <code>NIL</code>.  If <clix:arg>parameter-type</clix:arg>
1347             is <code>'STRING</code>,
1348             <clix:arg>var</clix:arg>'s value remains as is.
1349             If <clix:arg>parameter-type</clix:arg> is <code>'INTEGER</code>
1350             and the parameter string consists solely of decimal
1351             digits, <clix:arg>var</clix:arg>'s value will be the
1352             corresponding integer, otherwise <code>NIL</code>.
1353             If <clix:arg>parameter-type</clix:arg> is
1354             <code>'KEYWORD</code>, <clix:arg>var</clix:arg>'s value will be
1355             the keyword obtained
1356             by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_intern.htm">interning</a>
1357             the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stg_up.htm#string-upcase">upcased</a>
1358             parameter string into
1359             the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/11_abc.htm">keyword
1360               package</a>.  If <clix:arg>parameter-type</clix:arg>
1361             is <code>'CHARACTER</code> and the parameter string is of
1362             length one, <clix:arg>var</clix:arg>'s value will be the single
1363             character of this string, otherwise <code>NIL</code>.
1364             If <clix:arg>parameter-type</clix:arg>
1365             is <code>'BOOLEAN</code>, <clix:arg>var</clix:arg>'s value will
1366             always be <code>T</code> (unless it is <code>NIL</code> by the
1367             first rule above, of course).
1368             If <clix:arg>parameter-type</clix:arg> is any other atom, it is
1369             supposed to be
1370             a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_designator">function
1371               designator</a> for a unary function which will be called to
1372             convert the string to something else.
1373           </p>
1374           <p>
1375             Those were the rules for <em>simple</em> parameter types, but
1376             <clix:arg>parameter-type</clix:arg> can also be a list starting
1377             with one of the symbols
1378             <code>LIST</code>, <code>ARRAY</code>,
1379             or <code>HASH-TABLE</code>.  The second value of the list must
1380             always be a simple parameter type as in the last paragraph -
1381             we'll call it the <em>inner type</em> below.
1382           </p>
1383           <p>
1384             In the case of <code>'LIST</code>, all GET/POST parameters
1385             called <clix:arg>real-name</clix:arg> will be collected,
1386             converted to the inner type as by the rules above, and
1387             assembled into a list which will be the value of
1388             <clix:arg>var</clix:arg>.
1389           </p>
1390           <p>
1391             In the case of <code>'ARRAY</code>, all GET/POST parameters
1392             which have a name like the result of
1393           </p>
1394           <pre>(format nil "~A[~A]" real-name n)</pre>
1395           where <clix:arg>n</clix:arg> is a non-negative integer, will be
1396           assembled into an array where the <clix:arg>n</clix:arg>th element
1397           will be set accordingly, after conversion to the inner type.
1398           The array, which will become the value
1399           of <clix:arg>var</clix:arg>, will be big enough to hold all
1400           matching parameters, but not bigger.  Array elements not set as
1401           described above will be <code>NIL</code>.  Note
1402           that <code>VAR</code> will always be bound to an array, which
1403           may be empty, so it will never be <code>NIL</code>, even if no
1404           appropriate GET/POST parameters are found.
1405           <p>
1406             The full form of a <code>'HASH-TABLE</code> parameter type is
1407           </p>
1408           <pre>(hash-table inner-type key-type test-function)</pre>
1409           but <clix:arg>key-type</clix:arg>
1410           and <clix:arg>test-function</clix:arg> can be left out in which
1411           case they default to <code>'STRING</code>
1412           and <code>'EQUAL</code>, respectively.  For this parameter type,
1413           all GET/POST parameters which have a name like the result of
1414           <pre>(format nil "~A{~A}" real-name key)</pre>
1415           (where <clix:arg>key</clix:arg> is a string that doesn't contain
1416           curly brackets) will become the values (after conversion
1417           to <clix:arg>inner-type</clix:arg>) of a hash table with test
1418           function <clix:arg>test-function</clix:arg>
1419           where <clix:arg>key</clix:arg> (after conversion
1420           to <clix:arg>key-type</clix:arg>) will be the corresponding key.
1421           Note that <clix:arg>var</clix:arg> will always be bound to a hash
1422           table, which may be empty, so it will never be <code>NIL</code>,
1423           even if no appropriate GET/POST parameters are found.
1424           <p>
1425             To make matters even more complicated, the three compound
1426             parameter types also have an abbreviated form - just one of
1427             the symbols <code>LIST</code>, <code>ARRAY</code>,
1428             or <code>HASH-TABLE</code>.  In this case, the inner type will
1429             default to <code>'STRING</code>.
1430           </p>
1431           <p>
1432             If <clix:arg>parameter-type</clix:arg> is not provided
1433             or <code>NIL</code>, <clix:arg>default-parameter-type</clix:arg>
1434             (the default of which is <code>'STRING</code>) will be used
1435             instead.
1436           </p>
1437           <p>
1438             If the result of the computations above would be
1439             that <clix:arg>var</clix:arg> would be bound
1440             to <code>NIL</code>, then <clix:arg>init-form</clix:arg> (if
1441             provided) will be evaluated instead,
1442             and <clix:arg>var</clix:arg> will be bound to the result of this
1443             evaluation.
1444           </p>
1445           <p>
1446             Handlers built with this macro are constructed in such a way
1447             that the resulting Lisp function is useful even outside of
1448             Hunchentoot.  Specifically, all the parameter computations
1449             above will only happen if <clix:ref>*REQUEST*</clix:ref> is
1450             bound, i.e. if we're within a Hunchentoot request.
1451             Otherwise, <clix:arg>var</clix:arg> will always be bound to the
1452             result of evaluating <clix:arg>init-form</clix:arg> unless a
1453             corresponding keyword argument is provided.
1454           </p>
1455           <p>
1456             The <a href="#example">example code</a> that comes with
1457             Hunchentoot contains an example which demonstrates some of the
1458             features of <clix:ref>DEFINE-EASY-HANDLER</clix:ref>.
1459           </p>
1460         </clix:description>
1461       </clix:function>
1463       <clix:function name='dispatch-easy-handlers'>
1464         <clix:lambda-list>request
1465         </clix:lambda-list>
1466         <clix:returns>result
1467         </clix:returns>
1468         <clix:description>This is a dispatcher which returns the appropriate handler
1469         defined with <clix:ref>DEFINE-EASY-HANDLER</clix:ref>, if there is one.
1470         </clix:description>
1471       </clix:function>
1473     </clix:subchapter>
1475     <clix:subchapter name="requests" title="Request objects">
1477       For each incoming request, the <a href="#acceptors">acceptor</a> (in
1478       <clix:ref>PROCESS-CONNECTION</clix:ref>) creates a
1479       <clix:ref>REQUEST</clix:ref> object and makes it available to <a
1480       href="#request-dispatch">handlers</a> via the special variable
1481       <clix:ref>*REQUEST*</clix:ref>.  This object contains all relevant
1482       information about the request and this section collects the functions
1483       which can be used to query such an object.  In all function where
1484       <clix:arg>request</clix:arg> is an optional or keyword parameter, the
1485       default is <clix:ref>*REQUEST*</clix:ref>.
1487       <p>
1488         If you need more fine-grained control over the behaviour of request
1489         objects, you can subclass <clix:ref>REQUEST</clix:ref> and initialize
1490         the <a href="#acceptor-request-class"><code>REQUEST-CLASS</code></a>
1491         slot of the <clix:ref>ACCEPTOR</clix:ref> class accordingly.  The
1492         acceptor will generate request objects of the class named by this
1493         slot.
1494       </p>
1496       <clix:class name='request'>
1497         <clix:description>
1498           Objects of this class hold all the information
1499           about an incoming request.  They are created automatically by
1500           acceptors and can be accessed by the
1501           corresponding <a href="#request-dispatch">handler</a>.
1503           You should not mess with the slots of these objects directly, but you
1504           can subclass <clix:ref>REQUEST</clix:ref> in order to implement your
1505           own behaviour.  See
1506           the <a href="#acceptor-request-class"><code>REQUEST-CLASS</code></a>
1507           slot of the <clix:ref>ACCEPTOR</clix:ref> class.
1508         </clix:description>
1509       </clix:class>
1511       <clix:special-variable name='*request*'>
1512         <clix:description>The current REQUEST object while in the context of a request.
1513         </clix:description>
1514       </clix:special-variable>
1516       <clix:function name='real-remote-addr'>
1517         <clix:lambda-list>
1518           <clix:lkw>optional
1519           </clix:lkw> request
1520         </clix:lambda-list>
1521         <clix:returns>string{, list}
1522         </clix:returns>
1523         <clix:description>
1524           Returns the &#039;<code>X-Forwarded-For</code>&#039; incoming http header as the
1525           second value in the form of a list of IP addresses and the first
1526           element of this list as the first value if this header exists.
1527           Otherwise returns the value of <clix:ref>REMOTE-ADDR</clix:ref> as the only value.
1528         </clix:description>
1529       </clix:function>
1531       <clix:function name='parameter'>
1532         <clix:lambda-list>name
1533         <clix:lkw>optional
1534         </clix:lkw> request
1535         </clix:lambda-list>
1536         <clix:returns>string
1537         </clix:returns>
1538         <clix:description>
1539           Returns the GET or the POST parameter with name
1540           <clix:arg>name</clix:arg> (a string) - or <code>NIL</code>
1541           if there is none.  If both a GET and a POST parameter with
1542           the same name exist the GET parameter is returned.  Search
1543           is case-sensitive.  See also
1544           <clix:ref>GET-PARAMETER</clix:ref> and
1545           <clix:ref>POST-PARAMETER</clix:ref>.
1546         </clix:description>
1547       </clix:function>
1549       <clix:function name="get-parameter">
1550         <clix:lambda-list>name <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1551         <clix:returns>string</clix:returns>
1552         <clix:description>
1553           Returns the value of the GET parameter (as provided via the
1554           request URI) named by the string <clix:arg>name</clix:arg> as a
1555           string (or <code>NIL</code> if there ain't no GET parameter
1556           with this name). Note that only the first value will be
1557           returned if the client provided more than one GET parameter
1558           with the name <clix:arg>name</clix:arg>. See
1559           also <clix:ref>GET-PARAMETERS*</clix:ref>.
1560         </clix:description>
1561       </clix:function>
1563       <clix:function name="post-parameter">
1564         <clix:lambda-list>name <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1565         <clix:returns>string</clix:returns>
1566         <clix:description>
1567           Returns the value of the POST parameter (as provided in the
1568           request's body) named by the
1569           string <clix:arg>name</clix:arg>. Note that only the first value
1570           will be returned if the client provided more than one POST
1571           parameter with the name <clix:arg>name</clix:arg>.  This value
1572           will usually be a string (or <code>NIL</code> if there ain't
1573           no POST parameter with this name). If, however, the browser
1574           sent a <a class="none" name="upload">file</a> through
1575           a <a href="http://www.faqs.org/rfcs/rfc2388.html">
1576             <code>multipart/form-data</code>
1577           </a> form, the value of this function is a three-element list
1578           <pre>(path file-name content-type)</pre>
1579           where <clix:arg>path</clix:arg> is a pathname denoting the place
1580           were the uploaded file was
1581           stored, <clix:arg>file-name</clix:arg> (a string) is the file
1582           name sent by the browser, and <clix:arg>content-type</clix:arg>
1583           (also a string) is the content type sent by the browser. The
1584           file denoted by <clix:arg>path</clix:arg> will be deleted after
1585           the request has been handled - you have to move or copy it
1586           somewhere else if you want to keep it.
1587           <p>
1588             POST parameters will only be computed if the content type of
1589             the request body was <code>multipart/form-data</code>
1590             or <code>application/x-www-form-urlencoded</code>.  Although
1591             this function is called <code>POST-PARAMETER</code>, you can
1592             instruct Hunchentoot to compute these parameters for other
1593             request methods by
1594             setting <clix:ref>*METHODS-FOR-POST-PARAMETERS*</clix:ref>.
1595           </p>
1596           <p>
1597             See also <clix:ref>POST-PARAMETERS</clix:ref>
1598             and <clix:ref>*TMP-DIRECTORY*</clix:ref>.
1599           </p>
1600         </clix:description>
1601       </clix:function>
1603       <clix:function name="get-parameters*">
1604         <clix:lambda-list><clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1605         <clix:returns>alist</clix:returns>
1606         <clix:description>
1607           Returns
1608           an <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#alist">alist</a>
1609           of all GET parameters (as provided via the request
1610           URI). The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#car">car</a>
1611           of each element of this list is the parameter's name while
1612           the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#cdr">cdr</a>
1613           is its value (as a string). The elements of this list are in
1614           the same order as they were within the request URI. See
1615           also <clix:ref>GET-PARAMETER</clix:ref>.
1616         </clix:description>
1617       </clix:function>
1619       <clix:function name="post-parameters*">
1620         <clix:lambda-list><clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1621         <clix:returns>alist</clix:returns>
1622         <clix:description>
1623           Returns
1624           an <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#alist">alist</a>
1625           of all POST parameters (as provided via the request's
1626           body). The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#car">car</a>
1627           of each element of this list is the parameter's name while
1628           the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#cdr">cdr</a>
1629           is its value. The elements of this list are in the same order
1630           as they were within the request's body.
1631           <p>
1632             See also <clix:ref>POST-PARAMETER</clix:ref>.
1633           </p>
1634         </clix:description>
1635       </clix:function>
1637       <clix:special-variable name='*methods-for-post-parameters*'>
1638         <clix:description>A list of the request method types (as keywords) for which
1639         Hunchentoot will try to compute <clix:arg>post-parameters</clix:arg>.
1640         </clix:description>
1641       </clix:special-variable>
1643       <clix:function name='cookie-in'>
1644         <clix:lambda-list>name
1645         <clix:lkw>optional
1646         </clix:lkw> request
1647         </clix:lambda-list>
1648         <clix:returns>string
1649         </clix:returns>
1650         <clix:description>
1651           Returns the cookie with the name <clix:arg>name</clix:arg> (a string) as sent by the
1652           browser - or <code>NIL</code> if there is none.
1653         </clix:description>
1654       </clix:function>
1656       <clix:function name='cookies-in*'>
1657         <clix:lambda-list>
1658           <clix:lkw>optional
1659           </clix:lkw> request
1660         </clix:lambda-list>
1661         <clix:returns>alist
1662         </clix:returns>
1663         <clix:description>Returns an alist of all cookies associated with the <clix:ref>REQUEST</clix:ref> object
1664         <clix:arg>request</clix:arg>.
1665         </clix:description>
1666       </clix:function>
1668       <clix:function name='host'>
1669         <clix:lambda-list>
1670           <clix:lkw>optional
1671           </clix:lkw> request
1672         </clix:lambda-list>
1673         <clix:returns>host
1674         </clix:returns>
1675         <clix:description>Returns the &#039;Host&#039; incoming http header value.
1676         </clix:description>
1677       </clix:function>
1679       <clix:function name='query-string*'>
1680         <clix:lambda-list>
1681           <clix:lkw>optional
1682           </clix:lkw> request
1683         </clix:lambda-list>
1684         <clix:returns>string
1685         </clix:returns>
1686         <clix:description>
1687           Returns the query string of the <clix:ref>REQUEST</clix:ref> object <clix:arg>request</clix:arg>. That&#039;s
1688           the part behind the question mark (i.e. the GET parameters).
1689         </clix:description>
1690       </clix:function>
1692       <clix:function name='referer'>
1693         <clix:lambda-list>
1694           <clix:lkw>optional
1695           </clix:lkw> request
1696         </clix:lambda-list>
1697         <clix:returns>result
1698         </clix:returns>
1699         <clix:description>
1700           Returns the &#039;Referer&#039; (sic!) http header.
1701         </clix:description>
1702       </clix:function>
1704       <clix:function name='request-method*'>
1705         <clix:lambda-list>
1706           <clix:lkw>optional
1707           </clix:lkw> request
1708         </clix:lambda-list>
1709         <clix:returns>keyword
1710         </clix:returns>
1711         <clix:description>
1712           Returns the request method as a Lisp keyword.
1713         </clix:description>
1714       </clix:function>
1716       <clix:function name='request-uri*'>
1717         <clix:lambda-list>
1718           <clix:lkw>optional
1719           </clix:lkw> request
1720         </clix:lambda-list>
1721         <clix:returns>uri
1722         </clix:returns>
1723         <clix:description>
1724           Returns the request URI.
1725         </clix:description>
1726       </clix:function>
1728       <clix:function name='server-protocol*'>
1729         <clix:lambda-list>
1730           <clix:lkw>optional
1731           </clix:lkw> request
1732         </clix:lambda-list>
1733         <clix:returns>keyword
1734         </clix:returns>
1735         <clix:description>
1736           Returns the request protocol as a Lisp keyword.
1737         </clix:description>
1738       </clix:function>
1740       <clix:function name='user-agent'>
1741         <clix:lambda-list>
1742           <clix:lkw>optional
1743           </clix:lkw> request
1744         </clix:lambda-list>
1745         <clix:returns>result
1746         </clix:returns>
1747         <clix:description>
1748           Returns the &#039;User-Agent&#039; http header.
1749         </clix:description>
1750       </clix:function>
1752       <clix:function name='header-in*'>
1753         <clix:lambda-list>name
1754         <clix:lkw>optional
1755         </clix:lkw> request
1756         </clix:lambda-list>
1757         <clix:returns>header
1758         </clix:returns>
1759         <clix:description>
1760           Returns the incoming header with name
1761           <clix:arg>name</clix:arg>.  <clix:arg>name</clix:arg> can be
1762           a keyword (recommended) or a string.
1763         </clix:description>
1764       </clix:function>
1766       <clix:function name='headers-in*'>
1767         <clix:lambda-list>
1768           <clix:lkw>optional
1769           </clix:lkw> request
1770         </clix:lambda-list>
1771         <clix:returns>alist
1772         </clix:returns>
1773         <clix:description>
1774           Returns an alist of the incoming headers associated with the
1775           <clix:ref>REQUEST</clix:ref> object
1776           <clix:arg>request</clix:arg>.
1777         </clix:description>
1778       </clix:function>
1780       <clix:function name='remote-addr*'>
1781         <clix:lambda-list>
1782           <clix:lkw>optional
1783           </clix:lkw> request
1784         </clix:lambda-list>
1785         <clix:returns>address
1786         </clix:returns>
1787         <clix:description>
1788           Returns the address the current request originated from.
1789         </clix:description>
1790       </clix:function>
1792       <clix:function name='remote-port*'>
1793         <clix:lambda-list>
1794           <clix:lkw>optional
1795           </clix:lkw> request
1796         </clix:lambda-list>
1797         <clix:returns>port
1798         </clix:returns>
1799         <clix:description>
1800           Returns the port the current request originated from.
1801         </clix:description>
1802       </clix:function>
1804       <clix:function name='local-addr*'>
1805         <clix:lambda-list>
1806           <clix:lkw>optional
1807           </clix:lkw> request
1808         </clix:lambda-list>
1809         <clix:returns>address
1810         </clix:returns>
1811         <clix:description>
1812           The IP address of the local system that the client connected to.
1813         </clix:description>
1814       </clix:function>
1816       <clix:function name='local-port*'>
1817         <clix:lambda-list>
1818           <clix:lkw>optional
1819           </clix:lkw> request
1820         </clix:lambda-list>
1821         <clix:returns>port
1822         </clix:returns>
1823         <clix:description>
1824           The TCP port number of the local system that the client connected to.
1825         </clix:description>
1826       </clix:function>
1828       <clix:function name='script-name*'>
1829         <clix:lambda-list>
1830           <clix:lkw>optional
1831           </clix:lkw> request
1832         </clix:lambda-list>
1833         <clix:returns>script-name
1834         </clix:returns>
1835         <clix:description>
1836           Returns the file name of the <clix:ref>REQUEST</clix:ref>
1837           object <clix:arg>request</clix:arg>. That&#039;s the
1838           requested URI without the query string (i.e the GET
1839           parameters).
1840         </clix:description>
1841       </clix:function>
1843       <clix:accessor name='aux-request-value'>
1844         <clix:lambda-list>symbol
1845         <clix:lkw>optional
1846         </clix:lkw> request
1847         </clix:lambda-list>
1848         <clix:returns>value, present-p
1849         </clix:returns>
1850         <clix:description>
1851           This accessor can be used to associate arbitrary
1852           data with the the symbol <clix:arg>symbol</clix:arg> in the <clix:ref>REQUEST</clix:ref> object
1853           <clix:arg>request</clix:arg>. <clix:arg>present-p</clix:arg> is true if such data was found, otherwise <code>NIL</code>.
1854         </clix:description>
1855       </clix:accessor>
1857       <clix:function name='delete-aux-request-value'>
1858         <clix:lambda-list>symbol
1859         <clix:lkw>optional
1860         </clix:lkw> request
1861         </clix:lambda-list>
1862         <clix:returns>|
1863         </clix:returns>
1864         <clix:description>
1865           Removes the value associated with <clix:arg>symbol</clix:arg> from the <clix:ref>REQUEST</clix:ref> object
1866           <clix:arg>request</clix:arg>.
1867         </clix:description>
1868       </clix:function>
1870       <clix:function name='authorization'>
1871         <clix:lambda-list>
1872           <clix:lkw>optional
1873           </clix:lkw> request
1874         </clix:lambda-list>
1875         <clix:returns>result
1876         </clix:returns>
1877         <clix:description>
1878           Returns as two values the user and password (if any) as
1879           encoded in the &#039;AUTHORIZATION&#039; header.  Returns
1880           <code>NIL</code> if there is no such header.
1881         </clix:description>
1882       </clix:function>
1884       <clix:special-variable name='*hunchentoot-default-external-format*'>
1885         <clix:description>
1886           The external format used to compute the <clix:ref>REQUEST</clix:ref> object.
1887         </clix:description>
1888       </clix:special-variable>
1890       <clix:special-variable name='*file-upload-hook*'>
1891         <clix:description>
1892           If this is not <code>NIL</code>, it should be a unary
1893           function which will be called with a pathname for each file
1894           which is <a href="#upload">uploaded</a> to Hunchentoot.  The
1895           pathname denotes the temporary file to which the uploaded
1896           file is written.  The hook is called directly before the
1897           file is created. At this point,
1898           <clix:ref>*REQUEST*</clix:ref> is already bound to the
1899           current <clix:ref>REQUEST</clix:ref> object, but obviously
1900           you can't access the post parameters yet.
1901         </clix:description>
1902       </clix:special-variable>
1904       <clix:function name="raw-post-data">
1905         <clix:lambda-list>
1906           <clix:lkw>key</clix:lkw>
1907           request external-format force-text force-binary want-stream
1908         </clix:lambda-list>
1909         <clix:returns>raw-body-or-stream</clix:returns>
1910         <clix:description>
1911           Returns the content sent by the client in the request body if
1912           there was any (unless the content type
1913           was <code>multipart/form-data</code> in which
1914           case <code>NIL</code> is returned).  By default, the result is
1915           a string if the type of the <code>Content-Type</code>
1916           <a href="http://www.faqs.org/rfcs/rfc1590.html">media type</a>
1917           is <code>"text"</code>, and a vector of octets otherwise.  In
1918           the case of a string, the external format to be used to decode
1919           the content will be determined from the <code>charset</code>
1920           parameter sent by the client (or
1921           otherwise <clix:ref>*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT*</clix:ref>
1922           will be used).
1923           <p>
1924             You can also provide an external format explicitly (through
1925             <clix:arg>external-format</clix:arg>) in which case the result
1926             will unconditionally be a string.  Likewise, you can provide
1927             a true value for <clix:arg>force-text</clix:arg> which will
1928             force Hunchentoot to act as if the type of the media type
1929             had been <code>"text"</code>
1930             (with <clix:arg>external-format</clix:arg> taking precedence
1931             if provided).  Or you can provide a true value
1932             for <clix:arg>force-binary</clix:arg> which means that you
1933             want a vector of octets at any rate.  (If both
1934             <clix:arg>force-text</clix:arg>
1935             and <clix:arg>force-binary</clix:arg> are true, an error will
1936             be signaled.)
1937           </p>
1938           <p>
1939             If, however, you provide a true value
1940             for <clix:arg>want-stream</clix:arg>, the other parameters are
1941             ignored and you'll get the content (flexi) stream to read
1942             from it yourself.  It is then your responsibility to read
1943             the correct amount of data, because otherwise you won't be
1944             able to return a response to the client.  The stream will
1945             have
1946             its <a href="http://weitz.de/flexi-streams/#flexi-streams">octet
1947               position</a> set to <code>0</code>.  If the client provided
1948             a <code>Content-Length</code> header, the stream will also
1949             have a
1950             corresponding <a href="http://weitz.de/flexi-streams/#flexi-streams">bound</a>,
1951             so no matter whether the client used chunked encoding or
1952             not, you can always read until EOF.
1953           </p>
1954           <p>
1955             If the content type of the request
1956             was <code>multipart/form-data</code>
1957             or <code>application/x-www-form-urlencoded</code>, the
1958             content has been read by Hunchentoot already and you can't
1959             read from the stream anymore.
1960           </p>
1961           <p>
1962             You can call <clix:ref>RAW-POST-DATA</clix:ref> more than once
1963             per request, but you can't mix calls which have different
1964             values for <clix:arg>want-stream</clix:arg>.
1965           </p>
1966           <p>
1967             Note that this function is slightly misnamed because a
1968             client can send content even if the request method is not
1969             POST.
1970           </p>
1971         </clix:description>
1972       </clix:function>
1975       <clix:function name='recompute-request-parameters'>
1976         <clix:lambda-list>
1977           <clix:lkw>key
1978           </clix:lkw> request external-format
1979         </clix:lambda-list>
1980         <clix:returns>|
1981         </clix:returns>
1982         <clix:description>
1983           Recomputes the GET and POST parameters for the <clix:ref>REQUEST</clix:ref> object
1984           <clix:arg>request</clix:arg>.  This only makes sense if you&#039;re switching external formats
1985           during the request.
1986         </clix:description>
1987       </clix:function>
1989       <clix:function generic='true' name='process-request'>
1990         <clix:lambda-list>request
1991         </clix:lambda-list>
1992         <clix:returns>nil
1993         </clix:returns>
1994         <clix:description>
1995           This function is called by <clix:ref>PROCESS-CONNECTION</clix:ref>
1996           after the incoming headers have been read.  It
1997           calls <clix:ref>HANDLE-REQUEST</clix:ref> (and is more or less just a
1998           thin wrapper around it) to select and call a
1999           <a href="#request-dispatch">handler</a> and send the output of this handler to
2000           the client.  Note that <clix:ref>PROCESS-CONNECTION</clix:ref> is
2001           called once per connection and loops in case of a persistent
2002           connection while <clix:ref>PROCESS-REQUEST</clix:ref> is called anew
2003           for each request.
2004           <p>
2005             The return value of this function is ignored.
2006           </p>
2007           <p>
2008             Like <clix:ref>PROCESS-CONNECTION</clix:ref>, this is another function
2009             the behaviour of which you should only modify if you really, really
2010             know what you're doing.
2011           </p>
2012         </clix:description>
2013       </clix:function>
2015       <clix:function generic='true' name='handle-request'>
2016         <clix:lambda-list>acceptor request
2017         </clix:lambda-list>
2018         <clix:returns>content
2019         </clix:returns>
2020         <clix:description>
2021           This function is called by <clix:ref>PROCESS-REQUEST</clix:ref> once
2022           the request has been read and a <clix:ref>REQUEST</clix:ref> object
2023           has been created.  Its job is to actually handle the request, i.e. to
2024           return something to the client.
2025           <p>
2026             The default method calls the
2027             acceptor's <a href="#request-dispatch">request dispatcher</a>, but you
2028             can of course implement a different behaviour.  The default method
2029             also sets up <a href="#logging">standard error handling</a> for
2030             the <a href="#request-dispatch">handler</a>.
2031           </p>
2032           <p>
2033             Might be a good place to bind or rebind special variables which can
2034             then be accessed by your <a href="#request-dispatch">handlers</a>.
2035           </p>
2036         </clix:description>
2037       </clix:function>
2039       <clix:function generic='true' name='acceptor-dispatch-request'>
2040         <clix:lambda-list>acceptor request
2041         </clix:lambda-list>
2042         <clix:returns>content
2043         </clix:returns>
2044         <clix:description>
2045           This function is called to actually dispatch the request
2046           once the standard logging and error handling has been set
2047           up.  <clix:ref>ACCEPTOR</clix:ref> subclasses implement
2048           methods for this function in order to perform their own
2049           request routing.  If a method does not want to handle the
2050           request, it is supposed to invoke <a
2051           href="http://www.lispworks.com/documentation/HyperSpec/Body/f_call_n.htm">CALL-NEXT-METHOD</a>
2052           so that the next <clix:ref>ACCEPTOR</clix:ref> in the
2053           inheritance chain gets a chance to handle the request.
2054         </clix:description>
2055       </clix:function>
2057       <clix:readers generic='true'>
2058         <clix:listed-reader generic='true' name='cookies-in'>
2059           <clix:lambda-list>request
2060           </clix:lambda-list>
2061           <clix:returns>cookies
2062           </clix:returns>
2063         </clix:listed-reader>
2065         <clix:listed-reader generic='true' name='get-parameters'>
2066           <clix:lambda-list>request
2067           </clix:lambda-list>
2068           <clix:returns>get-parameters
2069           </clix:returns>
2070         </clix:listed-reader>
2072         <clix:listed-reader generic='true' name='header-in'>
2073           <clix:lambda-list>name request
2074           </clix:lambda-list>
2075           <clix:returns>result
2076           </clix:returns>
2077           <clix:description>
2078           </clix:description>
2079         </clix:listed-reader>
2081         <clix:listed-reader generic='true' name='headers-in'>
2082           <clix:lambda-list>request
2083           </clix:lambda-list>
2084           <clix:returns>headers
2085           </clix:returns>
2086         </clix:listed-reader>
2088         <clix:listed-reader generic='true' name='post-parameters'>
2089           <clix:lambda-list>request
2090           </clix:lambda-list>
2091           <clix:returns>post-parameters
2092           </clix:returns>
2093         </clix:listed-reader>
2095         <clix:listed-reader generic='true' name='query-string'>
2096           <clix:lambda-list>request
2097           </clix:lambda-list>
2098           <clix:returns>query-string
2099           </clix:returns>
2100         </clix:listed-reader>
2102         <clix:listed-reader generic='true' name='remote-addr'>
2103           <clix:lambda-list>request
2104           </clix:lambda-list>
2105           <clix:returns>address
2106           </clix:returns>
2107         </clix:listed-reader>
2109         <clix:listed-reader generic='true' name='remote-port'>
2110           <clix:lambda-list>request
2111           </clix:lambda-list>
2112           <clix:returns>port
2113           </clix:returns>
2114         </clix:listed-reader>
2116         <clix:listed-reader generic='true' name='local-addr'>
2117           <clix:lambda-list>request
2118           </clix:lambda-list>
2119           <clix:returns>address
2120           </clix:returns>
2121         </clix:listed-reader>
2123         <clix:listed-reader generic='true' name='local-port'>
2124           <clix:lambda-list>request
2125           </clix:lambda-list>
2126           <clix:returns>port
2127           </clix:returns>
2128         </clix:listed-reader>
2130         <clix:listed-reader generic='true' name='request-acceptor'>
2131           <clix:lambda-list>request
2132           </clix:lambda-list>
2133           <clix:returns>acceptor
2134           </clix:returns>
2135         </clix:listed-reader>
2137         <clix:listed-reader generic='true' name='request-method'>
2138           <clix:lambda-list>request
2139           </clix:lambda-list>
2140           <clix:returns>method
2141           </clix:returns>
2142         </clix:listed-reader>
2144         <clix:listed-reader generic='true' name='request-uri'>
2145           <clix:lambda-list>request
2146           </clix:lambda-list>
2147           <clix:returns>uri
2148           </clix:returns>
2149         </clix:listed-reader>
2151         <clix:listed-reader generic='true' name='server-protocol'>
2152           <clix:lambda-list>request
2153           </clix:lambda-list>
2154           <clix:returns>protocol
2155           </clix:returns>
2156         </clix:listed-reader>
2158         <clix:listed-reader generic='true' name='script-name'>
2159           <clix:lambda-list>request
2160           </clix:lambda-list>
2161           <clix:returns>result
2162           </clix:returns>
2163         </clix:listed-reader>
2165         <clix:description>
2166           These are various generic readers which are used
2167           to read information about a <clix:ref>REQUEST</clix:ref> object.  If you are writing a
2168           <a href="#request-dispatch">handler</a>, you should <em>not</em> use these readers but instead utilize the
2169           corresponding functions with an asterisk at the end of their name,
2170           also listed in this section.  These generic readers are only
2171           exported for users who want to create their own subclasses of
2172           <clix:ref>REQUEST</clix:ref>.
2173         </clix:description>
2175       </clix:readers>
2177     </clix:subchapter>
2179     <clix:subchapter name="replies" title="Reply objects">
2181       For each incoming request, the <a href="#acceptors">acceptor</a>
2182       (in <clix:ref>PROCESS-CONNECTION</clix:ref>) creates
2183       a <clix:ref>REPLY</clix:ref> object and makes it available
2184       to <a href="#request-dispatch">handlers</a> via the special variable
2185       <clix:ref>*REPLY*</clix:ref>.  This object contains all relevant
2186       information (except for the content body) about the reply that will be
2187       sent to the client and this section collects the functions which can
2188       be used to query and modify such an object.  In all function
2189       where <clix:arg>reply</clix:arg> is an optional or keyword parameter,
2190       the default is <clix:ref>*REPLY*</clix:ref>.
2192       <p>
2193         If you need more fine-grained control over the behaviour of reply
2194         objects, you can subclass <clix:ref>REPLY</clix:ref> and initialize
2195         the <a href="#acceptor-reply-class"><code>REPLY-CLASS</code></a>
2196         slot of the <clix:ref>ACCEPTOR</clix:ref> class accordingly.  The
2197         acceptor will generate reply objects of the class named by this
2198         slot.
2199       </p>
2201       <clix:class name='reply'>
2202         <clix:description>
2203           Objects of this class hold all the information about an
2204           outgoing reply.  They are created automatically by
2205           Hunchentoot and can be accessed and modified by the
2206           corresponding <a href="#request-dispatch">handler</a>.
2207         <p>
2208           You should not mess with the slots of these objects directly, but you
2209           can subclass <clix:ref>REPLY</clix:ref> in order to implement your own behaviour.  See the
2210           <a href="#acceptor-reply-class"><code>:reply-class</code></a> initarg
2211           of the <clix:ref>ACCEPTOR</clix:ref> class.
2212         </p>
2213         </clix:description>
2214       </clix:class>
2216       <clix:special-variable name='*reply*'>
2217         <clix:description>
2218           The current <clix:ref>REPLY</clix:ref> object in the context of a request.
2219         </clix:description>
2220       </clix:special-variable>
2222       <clix:accessor name='header-out'>
2223         <clix:lambda-list>name
2224         <clix:lkw>optional
2225         </clix:lkw> reply
2226         </clix:lambda-list>
2227         <clix:returns>string
2228         </clix:returns>
2229         <clix:description>
2230           <clix:ref>HEADER-OUT</clix:ref> returns the outgoing http header named by the keyword <clix:arg>name</clix:arg> if there is one, otherwise <code>NIL</code>. <code>SETF</code> of <clix:ref>HEADER-OUT</clix:ref> changes the current value of the header named <clix:arg>name</clix:arg>. If no header named <clix:arg>name</clix:arg> exists, it is created. For backwards compatibility, <clix:arg>name</clix:arg> can also be a string in which case the association between a header and its name is case-insensitive.
2231           <p>
2232             Note that the header 'Set-Cookie' cannot be queried by <clix:ref>HEADER-OUT</clix:ref> and must not be set by <code>SETF</code> of <clix:ref>HEADER-OUT</clix:ref>.
2233             See also <clix:ref>HEADERS-OUT*</clix:ref>, <clix:ref>CONTENT-TYPE*</clix:ref>, <clix:ref>CONTENT-LENGTH*</clix:ref>, <clix:ref>COOKIES-OUT*</clix:ref>, and <clix:ref>COOKIE-OUT</clix:ref>.
2234           </p>
2235         </clix:description>
2236       </clix:accessor>
2238       <clix:function name='headers-out*'>
2239         <clix:lambda-list>
2240           <clix:lkw>optional
2241           </clix:lkw> reply
2242         </clix:lambda-list>
2243         <clix:returns>alist
2244         </clix:returns>
2245         <clix:description>Returns an alist of the outgoing headers associated with the
2246         <clix:ref>REPLY</clix:ref> object <clix:arg>reply</clix:arg>.  See also <clix:ref>HEADER-OUT</clix:ref>.
2247         </clix:description>
2248       </clix:function>
2250       <clix:accessor name='content-length*'>
2251         <clix:lambda-list>
2252           <clix:lkw>optional
2253           </clix:lkw> reply
2254         </clix:lambda-list>
2255         <clix:returns>content-length
2256         </clix:returns>
2257         <clix:description>
2258           The outgoing &#039;Content-Length&#039; http header of <clix:arg>reply</clix:arg>.
2259         </clix:description>
2260       </clix:accessor>
2262       <clix:accessor name='content-type*'>
2263         <clix:lambda-list>
2264           <clix:lkw>optional
2265           </clix:lkw> reply
2266         </clix:lambda-list>
2267         <clix:returns>content-type
2268         </clix:returns>
2269         <clix:description>
2270           The outgoing &#039;Content-Type&#039; http header of <clix:arg>reply</clix:arg>.
2271         </clix:description>
2272       </clix:accessor>
2274       <clix:function name='cookie-out'>
2275         <clix:lambda-list>name
2276         <clix:lkw>optional
2277         </clix:lkw> reply
2278         </clix:lambda-list>
2279         <clix:returns>result
2280         </clix:returns>
2281         <clix:description>
2282           Returns the current value of the outgoing <a
2283           href="#cookies">cookie</a> named
2284           <clix:arg>name</clix:arg>. Search is case-sensitive.
2285         </clix:description>
2286       </clix:function>
2288       <clix:accessor name='cookies-out*'>
2289         <clix:lambda-list>
2290           <clix:lkw>optional
2291           </clix:lkw> reply
2292         </clix:lambda-list>
2293         <clix:returns>alist
2294         </clix:returns>
2295         <clix:description>
2296           Returns or sets an alist of the outgoing <a
2297           href="#cookies">cookies</a> associated with the
2298           <clix:ref>REPLY</clix:ref> object
2299           <clix:arg>reply</clix:arg>.
2300         </clix:description>
2301       </clix:accessor>
2303       <clix:accessor name='return-code*'>
2304         <clix:lambda-list>
2305           <clix:lkw>optional
2306           </clix:lkw> reply
2307         </clix:lambda-list>
2308         <clix:returns>return-code
2309         </clix:returns>
2310         <clix:description>
2311           Gets or sets the http return code of
2312           <clix:arg>reply</clix:arg>.  The return code of each
2313           <clix:ref>REPLY</clix:ref> object is initially set to
2314           <clix:ref>+HTTP-OK+</clix:ref>.
2315         </clix:description>
2316       </clix:accessor>
2318       <clix:function name="send-headers">
2319         <clix:returns>stream</clix:returns>
2320         <clix:description>
2321           Sends the initial status line and all headers as determined
2322           by the <clix:ref>REPLY</clix:ref>
2323           object <clix:ref>*REPLY*</clix:ref>.  Returns
2324           a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_b.htm#binary">binary</a>
2325           stream to which the body of the reply can be written.  Once
2326           this function has been called, further changes
2327           to <clix:ref>*REPLY*</clix:ref> don't have any effect.
2328           Also, automatic handling of errors (i.e. sending the
2329           corresponding status code to the browser, etc.) is turned
2330           off for this request and functions
2331           like <clix:ref>REDIRECT</clix:ref> or
2332           to <clix:ref>ABORT-REQUEST-HANDLER</clix:ref> won't have the
2333           desired effect once the headers are sent.
2334           <p>
2335             If your handlers return the full body as a string or as an
2336             array of octets, you should <em>not</em> call this function.
2337             If a handler calls <clix:ref>SEND-HEADERS</clix:ref> , its
2338             return value is ignored.
2339           </p>
2340         </clix:description>
2341       </clix:function>
2343       <clix:accessor name='reply-external-format*'>
2344         <clix:lambda-list>
2345           <clix:lkw>optional
2346           </clix:lkw> reply
2347         </clix:lambda-list>
2348         <clix:returns>external-format
2349         </clix:returns>
2350         <clix:description>
2351           Gets or sets the external format of <clix:arg>reply</clix:arg> which is used for character output.
2352         </clix:description>
2353       </clix:accessor>
2355       <clix:special-variable name='*default-content-type*'>
2356         <clix:description>
2357           The default content-type header which is returned to the client.
2358         </clix:description>
2359       </clix:special-variable>
2361       <clix:constants>
2362         <clix:listed-constant name="+http-continue+"/>
2363         <clix:listed-constant name="+http-switching-protocols+"/>
2364         <clix:listed-constant name="+http-ok+"/>
2365         <clix:listed-constant name="+http-created+"/>
2366         <clix:listed-constant name="+http-accepted+"/>
2367         <clix:listed-constant name="+http-non-authoritative-information+"/>
2368         <clix:listed-constant name="+http-no-content+"/>
2369         <clix:listed-constant name="+http-reset-content+"/>
2370         <clix:listed-constant name="+http-partial-content+"/>
2371         <clix:listed-constant name="+http-multi-status+"/>
2372         <clix:listed-constant name="+http-multiple-choices+"/>
2373         <clix:listed-constant name="+http-moved-permanently+"/>
2374         <clix:listed-constant name="+http-moved-temporarily+"/>
2375         <clix:listed-constant name="+http-see-other+"/>
2376         <clix:listed-constant name="+http-not-modified+"/>
2377         <clix:listed-constant name="+http-use-proxy+"/>
2378         <clix:listed-constant name="+http-temporary-redirect+"/>
2379         <clix:listed-constant name="+http-bad-request+"/>
2380         <clix:listed-constant name="+http-authorization-required+"/>
2381         <clix:listed-constant name="+http-payment-required+"/>
2382         <clix:listed-constant name="+http-forbidden+"/>
2383         <clix:listed-constant name="+http-not-found+"/>
2384         <clix:listed-constant name="+http-method-not-allowed+"/>
2385         <clix:listed-constant name="+http-not-acceptable+"/>
2386         <clix:listed-constant name="+http-proxy-authentication-required+"/>
2387         <clix:listed-constant name="+http-request-time-out+"/>
2388         <clix:listed-constant name="+http-conflict+"/>
2389         <clix:listed-constant name="+http-gone+"/>
2390         <clix:listed-constant name="+http-length-required+"/>
2391         <clix:listed-constant name="+http-precondition-failed+"/>
2392         <clix:listed-constant name="+http-request-entity-too-large+"/>
2393         <clix:listed-constant name="+http-request-uri-too-large+"/>
2394         <clix:listed-constant name="+http-unsupported-media-type+"/>
2395         <clix:listed-constant name="+http-requested-range-not-satisfiable+"/>
2396         <clix:listed-constant name="+http-expectation-failed+"/>
2397         <clix:listed-constant name="+http-failed-dependency+"/>
2398         <clix:listed-constant name="+http-internal-server-error+"/>
2399         <clix:listed-constant name="+http-not-implemented+"/>
2400         <clix:listed-constant name="+http-bad-gateway+"/>
2401         <clix:listed-constant name="+http-service-unavailable+"/>
2402         <clix:listed-constant name="+http-gateway-time-out+"/>
2403         <clix:listed-constant name="+http-version-not-supported+"/>
2404         <clix:description>
2405           The values of these constants are 100, 101, 200, 201, 202,
2406           203, 204, 205, 206, 207, 300, 301, 302, 303, 304, 305, 307,
2407           400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411,
2408           412, 413, 414, 415, 416, 417, 424, 500, 501, 502, 503, 504,
2409           and 505. See <clix:ref>RETURN-CODE</clix:ref>.
2410         </clix:description>
2411       </clix:constants>
2413       <clix:readers generic='true'>
2414         <clix:listed-reader generic='true' name='content-length'>
2415           <clix:lambda-list>reply
2416           </clix:lambda-list>
2417           <clix:returns>content-length
2418           </clix:returns>
2419         </clix:listed-reader>
2421         <clix:listed-reader generic='true' name='content-type'>
2422           <clix:lambda-list>reply
2423           </clix:lambda-list>
2424           <clix:returns>content-type
2425           </clix:returns>
2426         </clix:listed-reader>
2428         <clix:listed-reader generic='true' name='headers-out'>
2429           <clix:lambda-list>reply
2430           </clix:lambda-list>
2431           <clix:returns>headers-out
2432           </clix:returns>
2433         </clix:listed-reader>
2435         <clix:description>
2436           These are various generic readers which are used
2437           to read information about a <clix:ref>REPLY</clix:ref> object.  If you are writing a
2438           <a href="#request-dispatch">handler</a>, you should <em>not</em> use these readers but instead utilize the
2439           corresponding functions with an asterisk at the end of their name,
2440           also listed in this section.  These generic readers are only
2441           exported for users who want to create their own subclasses of
2442           <clix:ref>REPLY</clix:ref>.
2443         </clix:description>
2444       </clix:readers>
2446       <clix:accessors generic='true'>
2447         <clix:listed-accessor generic='true' name='cookies-out'>
2448           <clix:lambda-list>reply
2449           </clix:lambda-list>
2450           <clix:returns>result
2451           </clix:returns>
2452         </clix:listed-accessor>
2454         <clix:listed-accessor generic='true' name='return-code'>
2455           <clix:lambda-list>reply
2456           </clix:lambda-list>
2457           <clix:returns>result
2458           </clix:returns>
2459         </clix:listed-accessor>
2461         <clix:listed-accessor generic='true' name='reply-external-format'>
2462           <clix:lambda-list>reply
2463           </clix:lambda-list>
2464           <clix:returns>result
2465           </clix:returns>
2466         </clix:listed-accessor>
2468         <clix:description>
2469           These are various generic accessors which are
2470           used to query and modify a <clix:ref>REPLY</clix:ref> objects.  If
2471           you are writing a
2472           <a href="#request-dispatch">handler</a>, you should <em>not</em> use these
2473           accessors but instead utilize the corresponding functions with an
2474           asterisk at the end of their name, also listed in this section.
2475           These generic accessors are only exported for users who want to
2476           create their own subclasses of
2477           <clix:ref>REPLY</clix:ref>.
2478         </clix:description>
2479       </clix:accessors>
2482     </clix:subchapter>
2484     <clix:subchapter name="sessions" title="Sessions">
2485       Hunchentoot supports <em>sessions</em>: Once a <a href="#request-dispatch">request
2486       handler</a> has called <clix:ref>START-SESSION</clix:ref>, Hunchentoot
2487       uses either cookies or (if the client doesn't send the cookies
2488       back) <a href="#*rewrite-for-session-urls*">rewrites URLs</a> to keep
2489       track of this client, i.e. to provide a kind of 'state' for the
2490       stateless http protocol. The session associated with the client is a
2491       <a href="#session">CLOS object</a> which can be used
2492       to <a href="#session-value">store arbitrary data</a> between requests.
2493       <p>
2494         Hunchentoot makes some reasonable effort to prevent eavesdroppers from
2495         hijacking sessions (see below), but this should not be considered
2496         really secure. Don't store sensitive data in sessions and rely solely
2497         on the session mechanism as a safeguard against malicious users who
2498         want to get at this data!
2499       </p>
2500       <p>
2501         For each request there's one <clix:ref>SESSION</clix:ref> object which is accessible to the
2502         <a href="#handler">handler</a> via the special
2503         variable <clix:ref>*SESSION*</clix:ref>. This object holds all the
2504         information available about the session and can be accessed with the
2505         functions described in this chapter. Note that the internal structure
2506         of <clix:ref>SESSION</clix:ref> objects should be considered opaque
2507         and may change in future releases of Hunchentoot.
2508       </p>
2509       <p>
2510         Sessions are automatically <a href="#session-verify">verified</a> for
2511         validity and age when the <clix:ref>REQUEST</clix:ref> object is
2512         instantiated, i.e. if <clix:ref>*SESSION*</clix:ref> is not NIL then
2513         this session is valid (as far as Hunchentoot is concerned) and
2514         not <a href="#session-too-old-p">too old</a>.  Old sessions
2515         are <a href="#session-gc">automatically removed</a>.
2516       </p>
2518       <clix:class name='session'>
2519         <clix:description>
2520           <clix:ref>SESSION</clix:ref> objects are
2521           automatically maintained by Hunchentoot.  They should not be created
2522           explicitly with <code>MAKE-INSTANCE</code> but implicitly
2523           with <clix:ref>START-SESSION</clix:ref> and they should be treated as
2524           opaque objects.
2525           <p>
2526             You can ignore Hunchentoot's <clix:ref>SESSION</clix:ref> objects and
2527             <a href="#session-behaviour">implement your own sessions</a> if you provide corresponding methods for
2528             <clix:ref>SESSION-COOKIE-VALUE</clix:ref>
2529             and <clix:ref>SESSION-VERIFY</clix:ref>.
2530           </p>
2531         </clix:description>
2532       </clix:class>
2534       <clix:function name='start-session'>
2535         <clix:lambda-list>
2536         </clix:lambda-list>
2537         <clix:returns>session
2538         </clix:returns>
2539         <clix:description>
2540           Returns the current <clix:ref>SESSION</clix:ref>
2541           object. If there is no current session, creates one and updates the
2542           corresponding data structures. In this case the function will also
2543           send a session cookie to the browser.
2544         </clix:description>
2545       </clix:function>
2547       <clix:accessor name='session-value'>
2548         <clix:lambda-list>symbol
2549         <clix:lkw>optional
2550         </clix:lkw> session
2551         </clix:lambda-list>
2552         <clix:returns>value, present-p
2553         </clix:returns>
2554         <clix:description>
2555           This accessor can be used to associate arbitrary data with the the
2556           symbol <clix:arg>symbol</clix:arg> in the <clix:ref>SESSION</clix:ref>
2557           object <clix:arg>session</clix:arg>. <clix:arg>present-p</clix:arg> is
2558           true if such data was found, otherwise <code>NIL</code>. The default
2559           value for <clix:arg>session</clix:arg> is
2560           <clix:ref>*SESSION*</clix:ref>.
2561           <p>
2562             If <code>SETF</code> of <clix:ref>SESSION-VALUE</clix:ref> is called
2563             with <clix:arg>session</clix:arg> being <code>NIL</code> then a
2564             session is automatically instantiated
2565             with <clix:ref>START-SESSION</clix:ref>.
2566           </p>
2567         </clix:description>
2568       </clix:accessor>
2570       <clix:function name='delete-session-value'>
2571         <clix:lambda-list>symbol
2572         <clix:lkw>optional
2573         </clix:lkw> session
2574         </clix:lambda-list>
2575         <clix:returns>|
2576         </clix:returns>
2577         <clix:description>
2578           Removes the value associated with
2579           <clix:arg>symbol</clix:arg> from
2580           <clix:arg>session</clix:arg> if there is one.
2581         </clix:description>
2582       </clix:function>
2584       <clix:special-variable name='*session*'>
2585         <clix:description>
2586           The current session while in the context of a request, or
2587           <code>NIL</code>.
2588         </clix:description>
2589       </clix:special-variable>
2591       <clix:function name='remove-session'>
2592         <clix:lambda-list>session
2593         </clix:lambda-list>
2594         <clix:returns>|
2595         </clix:returns>
2596         <clix:description>
2597           Completely removes the <clix:ref>SESSION</clix:ref> object
2598           <clix:arg>session</clix:arg> from Hunchentoot&#039;s
2599           internal <a href="#session-db">session database</a>.
2600         </clix:description>
2601       </clix:function>
2603       <clix:function name='reset-sessions'>
2604         <clix:lambda-list>
2605           <clix:lkw>optional
2606           </clix:lkw> acceptor
2607         </clix:lambda-list>
2608         <clix:returns>|
2609         </clix:returns>
2610         <clix:description>
2611           Removes <em>all</em> stored sessions of
2612           <clix:arg>acceptor</clix:arg>.  The default for
2613           <clix:arg>acceptor</clix:arg> is
2614           <clix:ref>*ACCEPTOR*</clix:ref>.
2615         </clix:description>
2616       </clix:function>
2618       <clix:special-variable name='*rewrite-for-session-urls*'>
2619         <clix:description>
2620           Whether HTML pages should possibly be rewritten for cookie-less
2621           session-management.
2622         </clix:description>
2623       </clix:special-variable>
2625       <clix:special-variable name='*content-types-for-url-rewrite*'>
2626         <clix:description>
2627           The content types for which url-rewriting is OK. See
2628           <clix:ref>*REWRITE-FOR-SESSION-URLS*</clix:ref>.
2629         </clix:description>
2630       </clix:special-variable>
2632       <clix:special-variable name='*use-remote-addr-for-sessions*'>
2633         <clix:description>
2634           Whether the client&#039;s remote IP (as returned by <clix:ref>REAL-REMOTE-ADDR</clix:ref>)
2635           should be encoded into the session string.  If this value is true, a
2636           session will cease to be accessible if the client&#039;s remote IP changes.
2637           <p>
2638             This might for example be an issue if the client uses a proxy server
2639             which doesn&#039;t send correct &#039;X-Forwarded-For&#039; headers.
2640           </p>
2641         </clix:description>
2642       </clix:special-variable>
2644       <clix:function generic='true' name='session-remote-addr'>
2645         <clix:lambda-list>session
2646         </clix:lambda-list>
2647         <clix:returns>remote-addr
2648         </clix:returns>
2649         <clix:description>
2650           The remote IP address of the client when this session was started (as
2651           returned by <clix:ref>REAL-REMOTE-ADDR</clix:ref>).
2652         </clix:description>
2653       </clix:function>
2655       <clix:special-variable name='*use-user-agent-for-sessions*'>
2656         <clix:description>Whether the &#039;User-Agent&#039; header should
2657         be encoded into the session string.  If this value is true, a session
2658         will cease to be accessible if the client sends a different
2659         &#039;User-Agent&#039; header.
2660         </clix:description>
2661       </clix:special-variable>
2663       <clix:function generic='true' name='session-user-agent'>
2664         <clix:lambda-list>session
2665         </clix:lambda-list>
2666         <clix:returns>user-agent
2667         </clix:returns>
2668         <clix:description>
2669           The incoming &#039;User-Agent&#039; header that
2670           was sent when this session was created.
2671         </clix:description>
2672       </clix:function>
2674       <clix:accessor generic='true' name='session-max-time'>
2675         <clix:lambda-list>session
2676         </clix:lambda-list>
2677         <clix:returns>max-time
2678         </clix:returns>
2679         <clix:description>
2680           Gets or sets the time (in seconds) after
2681           which <clix:arg>session</clix:arg> expires if it's not used.
2682         </clix:description>
2683       </clix:accessor>
2686       <clix:special-variable name='*session-max-time*'>
2687         <clix:description>
2688           The default time (in seconds) after which a session times out.
2689         </clix:description>
2690       </clix:special-variable>
2692       <clix:special-variable name='*session-gc-frequency*'>
2693         <clix:description>
2694           A session GC (see function <clix:ref>SESSION-GC</clix:ref>) will happen every
2695           <clix:ref>*SESSION-GC-FREQUENCY*</clix:ref> requests (counting only
2696           requests which create a new session) if this variable is
2697           not <code>NIL</code>.  See <clix:ref>SESSION-CREATED</clix:ref>.
2698         </clix:description>
2699       </clix:special-variable>
2701       <clix:function name='session-gc'>
2702         <clix:lambda-list>
2703         </clix:lambda-list>
2704         <clix:returns>|
2705         </clix:returns>
2706         <clix:description>
2707           Removes sessions from the current session database which are
2708           too old - see <clix:ref>SESSION-TOO-OLD-P</clix:ref>.
2709         </clix:description>
2710       </clix:function>
2712       <clix:function name='session-too-old-p'>
2713         <clix:lambda-list>session
2714         </clix:lambda-list>
2715         <clix:returns>generalized-boolean
2716         </clix:returns>
2717         <clix:description>
2718           Returns true if the <clix:ref>SESSION</clix:ref> object <clix:arg>session</clix:arg> has not been active in
2719           the last <code>(session-max-time session)</code> seconds.
2720         </clix:description>
2721       </clix:function>
2723       <clix:function generic='true' name='session-id'>
2724         <clix:lambda-list>session
2725         </clix:lambda-list>
2726         <clix:returns>session-id
2727         </clix:returns>
2728         <clix:description>
2729           The unique ID (an INTEGER) of the session.
2730         </clix:description>
2731       </clix:function>
2733       <clix:function generic='true' name='session-start'>
2734         <clix:lambda-list>session
2735         </clix:lambda-list>
2736         <clix:returns>universal-time
2737         </clix:returns>
2738         <clix:description>
2739           The time this session was started.
2740         </clix:description>
2741       </clix:function>
2744     </clix:subchapter>
2746     <clix:subchapter name="session-behaviour" title="Customizing session behaviour">
2748       For everyday session usage, you will probably just
2749       use <clix:ref>START-SESSION</clix:ref>,
2750       <clix:ref>SESSION-VALUE</clix:ref>,
2751       and maybe <clix:ref>DELETE-SESSION-VALUE</clix:ref>
2752       and <clix:ref>*SESSION*</clix:ref>.  However, there are two ways to
2753       customize the way Hunchentoot maintains sessions.
2754       <p>
2755         One way is to mostly leave the session mechanism intact but to tweak
2756         it a bit:
2757         <ul>
2758           <li>The publicly visible part of a session is encoded using a
2759           <a href="#*session-secret*">secret</a> which you can set yourself.</li>
2760           <li>And it is stored using a cookie (or GET
2761           parameter) <a href="#session-cookie-name">name</a> that you can
2762           override.</li>
2763           <li>Each session receives a <a href="#next-session-id">new ID</a> when
2764           it is created and you can implement a more robust way to do that.</li>
2765           <li>You can arrange to be called whenever a session
2766           is <a href="#session-created">created</a> to trigger some action.  You
2767           might also do this to invent your own
2768           session <a href="#session-gc">garbage collection</a>.</li>
2769           <li>By default, all sessions are stored in a global alist in memory.
2770           You can't change the alist part, but you can distribute your sessions
2771           over different <a href="#session-db">"databases"</a>.</li>
2772           <li>By default, every operation which modifies sessions or one of the
2773           session databases is guarded by a global lock, but you can arrange to
2774           <a href="#session-db-lock">provide</a> different locks for this.</li>
2775         </ul>
2776       </p>
2777       <p>
2778         The other way to customize Hunchentoot's sessions is to completely
2779         replace them.  This is actually pretty easy: Create your own class to
2780         store state (which doesn't have to and probably shouldn't inherit
2781         from <clix:ref>SESSION</clix:ref>) and implement methods for
2782         <clix:ref>SESSION-VERIFY</clix:ref>
2783         and <clix:ref>SESSION-COOKIE-VALUE</clix:ref> - that's it.
2784         Hunchentoot will continue to use cookies and/or to rewrite URLs to
2785         keep track of session state and it will store "the current session"
2786         (whatever that is in your implementation)
2787         in <clix:ref>*SESSION*</clix:ref>.  Everything else (like persisting
2788         sessions, GC, getting and setting values) you'll have to take care of
2789         yourself and the other session functions
2790         (like <clix:ref>START-SESSION</clix:ref> or
2791         <clix:ref>SESSION-VALUE</clix:ref>) won't work anymore.  (Almost)
2792         total freedom, but a lot of responsibility as well... :)
2793       </p>
2795       <clix:special-variable name='*session-secret*'>
2796         <clix:description>
2797           A random ASCII string that&#039;s used to encode the public
2798           session data.  This variable is initially unbound and will
2799           be set (using <clix:ref>RESET-SESSION-SECRET</clix:ref>) the
2800           first time a session is created, if necessary.  You can
2801           prevent this from happening if you set the value yourself
2802           before starting <a href="#acceptors">acceptors</a>.
2803         </clix:description>
2804       </clix:special-variable>
2806       <clix:function name='reset-session-secret'>
2807         <clix:lambda-list>
2808         </clix:lambda-list>
2809         <clix:returns>secret
2810         </clix:returns>
2811         <clix:description>
2812           Sets <clix:ref>*SESSION-SECRET*</clix:ref> to a
2813           new random value. All old sessions will cease to be valid.
2814         </clix:description>
2815       </clix:function>
2817       <clix:function generic='true' name='session-cookie-name'>
2818         <clix:lambda-list>acceptor
2819         </clix:lambda-list>
2820         <clix:returns>name
2821         </clix:returns>
2822         <clix:description>
2823           Returns the name (a string) of the cookie (or
2824           the GET parameter) which is used to store a session on the client
2825           side.  The default is to use the
2826           string <code>&quot;hunchentoot-session&quot;</code>, but you can
2827           specialize this function if you want another name.
2828         </clix:description>
2829       </clix:function>
2831       <clix:function generic='true' name='session-created'>
2832         <clix:lambda-list>acceptor new-session
2833         </clix:lambda-list>
2834         <clix:returns>result
2835         </clix:returns>
2836         <clix:description>
2837           This function is called whenever a new session
2838           has been created.  There&#039;s a default method which might trigger
2839           a <a href="#session-gc">session GC</a> based on the value of
2840           <clix:ref>*SESSION-GC-FREQUENCY*</clix:ref>.
2841           <p>
2842             The return value is ignored.
2843           </p>
2844         </clix:description>
2845       </clix:function>
2847       <clix:function generic='true' name='next-session-id'>
2848         <clix:lambda-list>acceptor
2849         </clix:lambda-list>
2850         <clix:returns>id
2851         </clix:returns>
2852         <clix:description>
2853           Returns the next sequential session ID, an
2854           integer, which should be unique per session.  The default method uses
2855           a simple global counter and isn&#039;t guarded by a lock.  For a
2856           high-performance production environment you might consider using a
2857           more robust implementation.
2858         </clix:description>
2859       </clix:function>
2861       <clix:accessor generic='true' name='session-db'>
2862         <clix:lambda-list>acceptor
2863         </clix:lambda-list>
2864         <clix:returns>database
2865         </clix:returns>
2866         <clix:description>
2867           Returns the current session database which is an
2868           alist where each car is a session&#039;s ID and the cdr is the
2869           corresponding <clix:ref>SESSION</clix:ref> object itself.  The default
2870           is to use a global list for all acceptors.
2871         </clix:description>
2872       </clix:accessor>
2874       <clix:function generic='true' name='session-db-lock'>
2875         <clix:lambda-list>acceptor
2876         <clix:lkw>key
2877         </clix:lkw> whole-db-p
2878         </clix:lambda-list>
2879         <clix:returns>lock
2880         </clix:returns>
2881         <clix:description>
2882           A function which returns a lock that will be
2883           used to prevent concurrent access to sessions.  The first argument
2884           will be the <a href="#acceptors">acceptor</a> that handles the
2885           current <a href="#requests">request</a>, the second argument is true
2886           if the whole (current) session database is modified.  If it
2887           is <code>NIL</code>, only one existing session in the database is
2888           modified.
2889           <p>
2890             This function can return <code>NIL</code> which means that sessions or
2891             session databases will be modified without a lock held (for example
2892             for single-threaded environments).  The default is to always return a
2893             global lock (ignoring the <clix:arg>acceptor</clix:arg> argument) for
2894             Lisps that support threads and <code>NIL</code> otherwise.
2895           </p>
2896         </clix:description>
2897       </clix:function>
2899       <clix:function generic='true' name='session-verify'>
2900         <clix:lambda-list>request
2901         </clix:lambda-list>
2902         <clix:returns>session-or-nil
2903         </clix:returns>
2904         <clix:description>
2905           Tries to get a session identifier from the cookies
2906           (or alternatively from the GET parameters) sent by the client (see
2907           <clix:ref>SESSION-COOKIE-NAME</clix:ref>
2908           and <clix:ref>SESSION-COOKIE-VALUE</clix:ref>).  This identifier is
2909           then checked for validity against the <clix:ref>REQUEST</clix:ref>
2910           object
2911           <clix:arg>request</clix:arg>.  On success the corresponding session object (if not too
2912           old) is returned (and updated).  Otherwise <code>NIL</code> is returned.
2913           <p>
2914             A default method is provided and you only need to write your own one
2915             if you want to maintain your own sessions.
2916           </p>
2917         </clix:description>
2918       </clix:function>
2920       <clix:function generic='true' name='session-cookie-value'>
2921         <clix:lambda-list>session
2922         </clix:lambda-list>
2923         <clix:returns>string
2924         </clix:returns>
2925         <clix:description>
2926           Returns a string which can be used to safely
2927           restore the session <clix:arg>session</clix:arg> if as session has
2928           already been established.  This is used as the value stored in the
2929           session cookie or in the corresponding GET parameter and verified
2930           by <clix:ref>SESSION-VERIFY</clix:ref>.
2931           <p>
2932             A default
2933             method is provided and there&#039;s no reason to change it unless you
2934             want to use your own session objects.
2935           </p>
2936         </clix:description>
2937       </clix:function>
2939     </clix:subchapter>
2941     <clix:subchapter name="cookies" title="Cookies">
2943       Outgoing cookies are stored in the request's <clix:ref>REPLY</clix:ref>
2944       object (see <clix:ref>COOKIE-OUT</clix:ref>
2945       and <clix:ref>COOKIES-OUT*</clix:ref>). They are CLOS objects
2946       defined like this:
2948       <pre>(defclass cookie ()
2949   ((name :initarg :name
2950          :reader <a class="noborder" name="cookie-name">cookie-name</a>
2951          :type string
2952          :documentation "The name of the cookie - a string.")
2953    (value :initarg :value
2954           :accessor <a class="noborder" name="cookie-value">cookie-value</a>
2955           :initform ""
2956           :documentation "The value of the cookie. Will be URL-encoded when sent to the browser.")
2957    (expires :initarg :expires
2958             :initform nil
2959             :accessor <a class="noborder" name="cookie-expires">cookie-expires</a>
2960             :documentation "The time (a universal time) when the cookie expires (or NIL).")
2961    (path :initarg :path
2962          :initform nil
2963          :accessor <a class="noborder" name="cookie-path">cookie-path</a>
2964          :documentation "The path this cookie is valid for (or NIL).")
2965    (domain :initarg :domain
2966            :initform nil
2967            :accessor <a class="noborder" name="cookie-domain">cookie-domain</a>
2968            :documentation "The domain this cookie is valid for (or NIL).")
2969    (secure :initarg :secure
2970            :initform nil
2971            :accessor <a class="noborder" name="cookie-secure">cookie-secure</a>
2972            :documentation "A generalized boolean denoting whether this is a secure cookie.")
2973    (http-only :initarg :http-only
2974               :initform nil
2975               :accessor <a class="noborder" name="cookie-http-only">cookie-http-only</a>
2976               :documentation "A generalized boolean denoting whether this is a <a href="http://msdn2.microsoft.com/en-us/library/ms533046.aspx">HttpOnly</a> cookie.")))
2977       </pre>
2979       The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_r.htm#reader">reader</a>
2980       <clix:ref>COOKIE-NAME</clix:ref> and
2981       the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#accessor">accessors</a>
2982       <clix:ref>COOKIE-VALUE</clix:ref>, <clix:ref>COOKIE-EXPIRES</clix:ref>,
2983       <clix:ref>COOKIE-PATH</clix:ref>, <clix:ref>COOKIE-DOMAIN</clix:ref>, <clix:ref>COOKIE-SECURE</clix:ref>,
2984       and <clix:ref>COOKIE-HTTP-ONLY</clix:ref> are all exported from
2985       the <code>HUNCHENTOOT</code> package.  For now, the class name itself is <em>not</em> exported.
2987       <clix:function name="set-cookie">
2988         <clix:lambda-list>
2989           name <clix:lkw>key</clix:lkw> value expires path
2990           domain secure http-only reply
2991         </clix:lambda-list>
2992         <clix:returns>cookie</clix:returns>
2993         <clix:description>
2994           Creates a <code>COOKIE</code> object from the parameters
2995           provided to this function and adds it to the outgoing cookies
2996           of the <a href="#replies"><code>REPLY</code> object</a>
2997           <clix:arg>reply</clix:arg>. If a cookie with the same name
2998           (case-sensitive) already exists, it is replaced. The default
2999           for <clix:arg>reply</clix:arg>
3000           is <clix:ref>*REPLY*</clix:ref>. The default
3001           for <clix:arg>value</clix:arg> is the empty string.
3002         </clix:description>
3003       </clix:function>
3005       <clix:function name="set-cookie*">
3006         <clix:lambda-list>cookie <clix:lkw>optional</clix:lkw> reply</clix:lambda-list>
3007         <clix:returns>cookie</clix:returns>
3008         <clix:description>
3009           Adds the <code>COOKIE</code> object <clix:arg>cookie</clix:arg>
3010           to the outgoing cookies of
3011           the <a href="#replies"><code>REPLY</code> object</a>
3012           <clix:arg>reply</clix:arg>. If a cookie with the same name
3013           (case-sensitive) already exists, it is replaced. The default
3014           for <clix:arg>reply</clix:arg> is <clix:ref>*REPLY*</clix:ref>.
3015         </clix:description>
3016       </clix:function>
3017     </clix:subchapter>
3019     <clix:subchapter name="logging" title="Logging">
3020       Hunchentoot can log accesses and diagnostic messages to two
3021       separate destinations, which can be either files in the file
3022       system or streams.  Logging can also be disabled by setting the
3023       <clix:code>ACCESS-LOG-DESTINATION</clix:code> and
3024       <clix:code>MESSAGE-LOG-DESTINATION</clix:code> slots in the
3025       <clix:ref>ACCEPTOR</clix:ref> to <code>NIL</code>.  The two
3026       slots can be initialized by providing the
3027       :ACCESS-LOG-DESTINATION and :MESSAGE-LOG-DESTINATION
3028       initialization arguments when creating the acceptor or set by
3029       setting the slots through its
3030       <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref> and
3031       <clix:ref>ACCEPTOR-ACCESS-LOG-DESTINATION</clix:ref> accessors.
3032       <p>
3033         When the path for the message or accept log is set to a
3034         variable holding an output stream, hunchentoots writes
3035         corresponding log entries to that stream.  By default,
3036         Hunchentoot logs to *STANDARD-ERROR*.
3037       </p>
3038       <p>
3039         Access logging is done in a format similar to what
3040         the Apache web server can write so that logfile analysis using
3041         standard tools is possible.  Errors during request processing are
3042         logged to a separate file.
3043       </p>
3044       <p>
3045         The standard logging mechanism is deliberately simple and slow.  The
3046         log files are opened for each log entry and closed again after
3047         writing, and access to them is protected by a global lock.  Derived
3048         acceptor classes can implement methods for the
3049         <clix:ref>ACCEPTOR-LOG-MESSAGE</clix:ref> and
3050         <clix:ref>ACCEPTOR-LOG-ACCESS</clix:ref> generic functions in order to
3051         log differently (e.g. to a central logging server or in a different
3052         file format.
3053       </p>
3054       <p>
3055         Errors happening within a <a href="#request-dispatch">handler</a>
3056         which are not caught by the handler itself are handled by
3057         Hunchentoot by logging them to the established
3058         <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref>.
3059       </p>
3061       <clix:function name='log-message*'>
3062         <clix:lambda-list>log-level format-string
3063         <clix:lkw>rest
3064         </clix:lkw> format-arguments
3065         </clix:lambda-list>
3066         <clix:returns>result
3067         </clix:returns>
3068         <clix:description>
3069           Convenience function which calls the message
3070           logger of the current acceptor (if there is one) with the same
3071           arguments it accepts.  Returns <code>NIL</code> if there is no message
3072           logger or whatever the message logger returns.
3073           <p>
3074             This is the function which Hunchentoot itself uses to log errors it
3075             catches during request processing.
3076           </p>
3077         </clix:description>
3078       </clix:function>
3080       <clix:special-variable name='*log-lisp-errors-p*'>
3081         <clix:description>
3082           Whether Lisp errors in request handlers should be logged.
3083         </clix:description>
3084       </clix:special-variable>
3086       <clix:special-variable name='*log-lisp-backtraces-p*'>
3087         <clix:description>
3088           Whether Lisp backtraces should be logged.  Only
3089           has an effect if <clix:ref>*LOG-LISP-ERRORS-P*</clix:ref> is true
3090           as well.
3091         </clix:description>
3092       </clix:special-variable>
3094       <clix:special-variable name='*log-lisp-warnings-p*'>
3095         <clix:description>
3096           Whether Lisp warnings in request handlers should be logged.
3097         </clix:description>
3098       </clix:special-variable>
3100       <clix:special-variable name='*lisp-errors-log-level*'>
3101         <clix:description>
3102           Log level for Lisp errors.  Should be one
3103           of <code>:ERROR</code> (the default), <code>:WARNING</code>,
3104           or <code>:INFO</code>.
3105         </clix:description>
3106       </clix:special-variable>
3108       <clix:special-variable name='*lisp-warnings-log-level*'>
3109         <clix:description>
3110           Log level for Lisp warnings.
3111           Should be one of <code>:ERROR</code>, <code>:WARNING</code>
3112           (the default), or <code>:INFO</code>.
3113         </clix:description>
3114       </clix:special-variable>
3115     </clix:subchapter>
3117     <clix:subchapter name="conditions" title="Conditions and error handling">
3118       <p>
3119         This section describes how Hunchentoot deals with exceptional
3120         situations.  See also the secion about <a href="#logging">logging</a>.
3121       </p>
3122       <p>
3123         When an error occurs while processing a request, Hunchentoot's
3124         default behavior is to catch catch the error, log it and
3125         optionally display it to the client in the HTML response.
3126         This behavior can be customized through the values of a number
3127         of special variables, which are documented below.
3128       </p>
3130       <clix:special-variable name='*catch-errors-p*'>
3131         <clix:description>
3132           If the value of this variable is <code>NIL</code>
3133           (the default is <code>T</code>), then errors which happen while a
3134           request is handled aren't <a href="#logging">caught as usual</a>, but
3135           instead your
3136           Lisp's <a
3137           href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_d.htm#debugger">debugger</a>
3138           is <a
3139           href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invoke.htm">invoked</a>.
3140           This variable should obviously always be set to a <em>true</em> value
3141           in a production environment.
3142           See <clix:ref>MAYBE-INVOKE-DEBUGGER</clix:ref>
3143           if you want to fine-tune this behaviour.
3144         </clix:description>
3145       </clix:special-variable>
3147       <clix:special-variable name='*show-lisp-errors-p*'>
3148         <clix:description>
3149           Whether Lisp errors should be shown in HTML output.  Note
3150           that this only affects canned responses generated by Lisp.
3151           If an error template is present for the "internal server
3152           error" status code, this special variable is not used (see
3153           <clix:ref>acceptor-status-message</clix:ref>).
3154         </clix:description>
3155       </clix:special-variable>
3157       <clix:special-variable name='*show-lisp-backtraces-p*'>
3158         <clix:description>
3159           Whether Lisp backtraces should be shown in HTML output if
3160           <clix:ref>*SHOW-LISP-ERRORS-P*</clix:ref> is true and an error occurs.
3161         </clix:description>
3162       </clix:special-variable>
3164       <clix:function generic='true' name='maybe-invoke-debugger'>
3165         <clix:lambda-list>condition
3166         </clix:lambda-list>
3167         <clix:returns>|
3168         </clix:returns>
3169         <clix:description>
3170           This generic function is called whenever a
3171           <a
3172               href="http://www.lispworks.com/documentation/HyperSpec/Body/09_.htm">condition</a> <code><i>condition</i></code>
3173           is signaled in Hunchentoot.  You might want to specialize it on
3174           specific condition classes for debugging purposes.  The default
3175           method <a
3176           href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invoke.htm">invokes
3177           the debugger</a> with <clix:arg>condition</clix:arg> if
3178           <clix:ref>*CATCH-ERRORS-P*</clix:ref> is <code>NIL</code>.
3179         </clix:description>
3180       </clix:function>
3182       <clix:condition name='hunchentoot-condition'>
3183         <clix:description>
3184           Superclass for all conditions related to Hunchentoot.
3185         </clix:description>
3186       </clix:condition>
3188       <clix:condition name='hunchentoot-error'>
3189         <clix:description>
3190           Superclass for all errors related to Hunchentoot and a subclass of <clix:ref>HUNCHENTOOT-CONDITION</clix:ref>.
3191         </clix:description>
3192       </clix:condition>
3194       <clix:condition name='parameter-error'>
3195         <clix:description>
3196           Signalled if a function was called with incosistent or illegal parameters.  A subclass of <clix:ref>HUNCHENTOOT-ERROR</clix:ref>.
3197         </clix:description>
3198       </clix:condition>
3200       <clix:condition name='hunchentoot-warning'>
3201         <clix:description>
3202           Superclass for all warnings related to Hunchentoot and a subclass of <clix:ref>HUNCHENTOOT-CONDITION</clix:ref>.
3203         </clix:description>
3204       </clix:condition>
3206     </clix:subchapter>
3208     <clix:subchapter name="misc" title="Miscellaneous">
3210       Various functions and variables which didn't fit into one of the
3211       other categories.
3213       <clix:function name='abort-request-handler'>
3214         <clix:lambda-list>
3215           <clix:lkw>optional
3216           </clix:lkw> result
3217         </clix:lambda-list>
3218         <clix:returns>result
3219         </clix:returns>
3220         <clix:description>
3221           This function can be called by a request handler
3222           at any time to immediately abort handling the request.  This works as
3223           if the handler had returned <clix:arg>result</clix:arg>.  See the
3224           source code of <clix:ref>REDIRECT</clix:ref> for an example.
3225         </clix:description>
3226       </clix:function>
3228       <clix:function name="handle-if-modified-since">
3229         <clix:lambda-list>time <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
3230         <clix:returns>|</clix:returns>
3231         <clix:description>
3232           This function is designed to be used inside
3233           a <a href="#request-dispatch">handler</a>. If the client has sent an
3234           'If-Modified-Since' header
3235           (see <a href="http://www.faqs.org/rfcs/rfc2616.html">RFC 2616</a>,
3236           section 14.25) and the time specified matches the universal
3237           time
3238           <clix:arg>time</clix:arg> then the
3239           header <clix:ref>+HTTP-NOT-MODIFIED+</clix:ref> with no content
3240           is immediately returned to the client.
3241           <p>
3242             Note that for this function to be useful you should usually
3243             send 'Last-Modified' headers back to the client. See the
3244             code
3245             of <clix:ref>CREATE-STATIC-FILE-DISPATCHER-AND-HANDLER</clix:ref>
3246             for an example.
3247           </p>
3248         </clix:description>
3249       </clix:function>
3251       <clix:function name="handle-static-file">
3252         <clix:lambda-list>path <clix:lkw>optional</clix:lkw> content-type</clix:lambda-list>
3253         <clix:returns>nil</clix:returns>
3254         <clix:description>
3255           Sends the file denoted by the pathname designator
3256           <clix:arg>path</clix:arg> with content type
3257           <clix:arg>content-type</clix:arg> to the client.  Sets the
3258           necessary handlers.  In particular the function employs
3259           <clix:ref>HANDLE-IF-MODIFIED-SINCE</clix:ref>.
3260           <p>
3261             If <clix:arg>content-type</clix:arg> is <code>NIL</code> the
3262             function tries to determine the correct content type from
3263             the file's suffix or falls back
3264             to <code>"application/octet-stream"</code> as a last resort.
3265           </p>
3266           <p>
3267             Note that this function
3268             calls <clix:ref>SEND-HEADERS</clix:ref> internally, so after
3269             you've called it, the headers are sent and the return value
3270             of your handler is ignored.
3271           </p>
3272         </clix:description>
3273       </clix:function>
3275       <clix:function name="redirect">
3276         <clix:lambda-list>target <clix:lkw>key</clix:lkw> host port protocol add-session-id code</clix:lambda-list>
3277         <clix:returns>|</clix:returns>
3278         <clix:description>
3279           Sends back appropriate headers to redirect the client
3280           to <clix:arg>target</clix:arg> (a string).
3281           <p>
3282             If <clix:arg>target</clix:arg> is a full URL starting with a
3283             scheme, <clix:arg>host</clix:arg>, <clix:arg>port</clix:arg>,
3284             and <clix:arg>protocol</clix:arg> are ignored.
3285             Otherwise, <clix:arg>target</clix:arg> should denote the path
3286             part of a URL, <clix:arg>protocol</clix:arg> must be one of
3287             the keywords <code>:HTTP</code> or <code>:HTTPS</code>, and
3288             the URL to redirect to will be constructed
3289             from <clix:arg>host</clix:arg>, <clix:arg>port</clix:arg>, <clix:arg>protocol</clix:arg>,
3290             and <clix:arg>target</clix:arg>.
3291           </p>
3292           <p>
3293             <clix:arg>code</clix:arg> must be a 3xx HTTP redirection
3294             status code to send to the client.  It defaults to 302
3295             ("Found").  If <clix:arg>host</clix:arg> is not provided,
3296             the current host (see <clix:ref>HOST</clix:ref>) will be
3297             used. If <clix:arg>protocol</clix:arg> is the keyword
3298             <code>:HTTPS</code>, the client will be redirected to a
3299             https URL, if it's <code>:HTTP</code> it'll be sent to a
3300             http URL.  If both <clix:arg>host</clix:arg> and
3301             <clix:arg>protocol</clix:arg> aren't provided, then the
3302             value of <clix:arg>protocol</clix:arg> will match the
3303             current request.
3304           </p>
3305         </clix:description>
3306       </clix:function>
3308       <clix:function name="require-authorization">
3309         <clix:lambda-list><clix:lkw>optional</clix:lkw> realm</clix:lambda-list>
3310         <clix:returns>|</clix:returns>
3311         <clix:description>
3312           Sends back appropriate headers to require basic HTTP
3313           authentication
3314           (see <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617</a>)
3315           for the realm <clix:arg>realm</clix:arg>. The default value
3316           for <clix:arg>realm</clix:arg> is <code>"Hunchentoot"</code>.
3317         </clix:description>
3318       </clix:function>
3320       <clix:function name='no-cache'>
3321         <clix:lambda-list>
3322         </clix:lambda-list>
3323         <clix:returns>|
3324         </clix:returns>
3325         <clix:description>
3326           Adds appropriate headers to completely prevent caching on most browsers.
3327         </clix:description>
3328       </clix:function>
3330       <clix:function name='ssl-p'>
3331         <clix:lambda-list>
3332           <clix:lkw>optional
3333           </clix:lkw> acceptor
3334         </clix:lambda-list>
3335         <clix:returns>generalized-boolean
3336         </clix:returns>
3337         <clix:description>
3338           Whether the current connection to the client is secure.  See <clix:ref>ACCEPTOR-SSL-P</clix:ref>.
3339         </clix:description>
3340       </clix:function>
3342       <clix:function name='reason-phrase'>
3343         <clix:lambda-list>return-code
3344         </clix:lambda-list>
3345         <clix:returns>string
3346         </clix:returns>
3347         <clix:description>
3348           Returns a reason phrase for the HTTP return code <clix:arg>return-code</clix:arg>
3349           (which should be an integer) or <code>NIL</code> for return codes Hunchentoot
3350           doesn&#039;t know.
3351         </clix:description>
3352       </clix:function>
3354       <clix:function name='rfc-1123-date'>
3355         <clix:lambda-list>
3356           <clix:lkw>optional
3357           </clix:lkw> time
3358         </clix:lambda-list>
3359         <clix:returns>string
3360         </clix:returns>
3361         <clix:description>
3362           Generates a time string according to <a href="http://www.faqs.org/rfcs/rfc1123.html">RFC 1123</a>.  Default is current time.
3363           This can be used to send a 'Last-Modified' header - see <clix:ref>HANDLE-IF-MODIFIED-SINCE</clix:ref>.
3364         </clix:description>
3365       </clix:function>
3367       <clix:function name='url-encode'>
3368         <clix:lambda-list>string
3369         <clix:lkw>optional
3370         </clix:lkw> external-format
3371         </clix:lambda-list>
3372         <clix:returns>string
3373         </clix:returns>
3374         <clix:description>
3375           URL-encodes a string using the external format <clix:arg>external-format</clix:arg>.  The default for <clix:arg>external-format</clix:arg> is the value of <clix:ref>*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT*</clix:ref>.
3376         </clix:description>
3377       </clix:function>
3379       <clix:function name='url-decode'>
3380         <clix:lambda-list>string
3381         <clix:lkw>optional
3382         </clix:lkw> external-format
3383         </clix:lambda-list>
3384         <clix:returns>string
3385         </clix:returns>
3386         <clix:description>
3387           Decodes a URL-encoded string which is assumed to
3388           be encoded using the external
3389           format <clix:arg>external-format</clix:arg>, i.e. this is the inverse
3390           of <clix:ref>URL-ENCODE</clix:ref>. It is assumed that you'll rarely
3391           need this function, if ever. But just in case - here it is.  The
3392           default for <clix:arg>external-format</clix:arg> is the value
3393           of <clix:ref>*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT*</clix:ref>.
3394         </clix:description>
3395       </clix:function>
3397       <clix:function name='escape-for-html'>
3398         <clix:lambda-list>string
3399         </clix:lambda-list>
3400         <clix:returns>result
3401         </clix:returns>
3402         <clix:description>
3403           Escapes the characters #\&lt;, #\&gt;, #\&#039;, #\&quot;, and #\&amp; for HTML output.
3404         </clix:description>
3405       </clix:function>
3407       <clix:function name="http-token-p">
3408         <clix:lambda-list>object</clix:lambda-list>
3409         <clix:returns>generalized-boolean</clix:returns>
3410         <clix:description>
3411           This function tests whether <clix:arg>object</clix:arg> is a
3412           non-empty string which is a <em>token</em> according
3413           to <a href="http://www.faqs.org/rfcs/rfc2068.html">RFC
3414           2068</a> (i.e. whether it may be used for, say, cookie names).
3415         </clix:description>
3416       </clix:function>
3418       <clix:function name='mime-type'>
3419         <clix:lambda-list>pathspec
3420         </clix:lambda-list>
3421         <clix:returns>result
3422         </clix:returns>
3423         <clix:description>
3424           Given a pathname designator <clix:arg>pathspec</clix:arg> returns the <a href="http://en.wikipedia.org/wiki/Internet_media_type">MIME type</a>
3425           (as a string) corresponding to the suffix of the file denoted by
3426           <clix:arg>pathspec</clix:arg> (or <code>NIL</code>).
3427         </clix:description>
3428       </clix:function>
3430       <clix:function name='within-request-p'>
3431         <clix:lambda-list>
3432         </clix:lambda-list>
3433         <clix:returns>generalized-boolean
3434         </clix:returns>
3435         <clix:description>
3436           Returns true if in the context of a request. Otherwise, <code>NIL</code>.
3437         </clix:description>
3438       </clix:function>
3440       <clix:special-variable name="*tmp-directory*">
3441         <clix:description>
3442           This should be a pathname denoting a directory where temporary
3443           files can be stored. It is used for <a href="#upload">file
3444           uploads</a>.
3445         </clix:description>
3446       </clix:special-variable>
3448       <clix:special-variable name='*header-stream*'>
3449         <clix:description>
3450           If this variable is not <code>NIL</code>, it should be bound to a stream to
3451           which incoming and outgoing headers will be written for debugging
3452           purposes.
3453         </clix:description>
3454       </clix:special-variable>
3457       <clix:special-variable name='*cleanup-function*'>
3458         <clix:description>
3459           A designator for a function without arguments which is called on a
3460           regular basis if <clix:ref>*CLEANUP-INTERVAL*</clix:ref> is not <code>NIL</code>.  The initial value is
3461           the name of a function which invokes a garbage collection on 32-bit
3462           versions of LispWorks.
3463           <p>
3464             This variable is only available on LispWorks.
3465           </p>
3466         </clix:description>
3467       </clix:special-variable>
3469       <clix:special-variable name='*cleanup-interval*'>
3470         <clix:description>
3471           Should be <code>NIL</code> or a positive integer.  The system calls
3472           <clix:ref>*CLEANUP-FUNCTION*</clix:ref>
3473           whenever <clix:ref>*CLEANUP-INTERVAL*</clix:ref> new worker threads
3474           (counted globally across all acceptors) have been created unless the
3475           value is <code>NIL</code>.  The initial value is 100.
3476           <p>
3477             This variable is only available on LispWorks.
3478           </p>
3479         </clix:description>
3480       </clix:special-variable>
3481     </clix:subchapter>
3482   </clix:chapter>
3484   <clix:chapter name="testing" title="Testing">
3485     Hunchentoot comes with a test script which verifies that the
3486     example web server responds as expected.  This test script uses the
3487     <a href="http://weitz.de/drakma/">Drakma</a> HTTP client library
3488     and thus shares a significant amount of its base code with
3489     Hunchentoot itself.  Still, running the test script is a useful
3490     confidence test, and it is also possible to run the script across
3491     machines in order to verify a new Hunchentoot (or, for that matter
3492     Drakma) port.
3493     <p>
3494       To run the confidence test, <a href="#start">start
3495       the example web server</a>.  Then, in your Lisp
3496       listener, type
3497 <pre>(<a class="noborder" href="hunchentoot-test:test-hunchentoot">hunchentoot-test:test-hunchentoot</a> "http://localhost:4242")</pre>
3498 You will see some diagnostic output and a summary line that
3499 reports whether any tests have failed.  (You can also use the
3500 example certificate and key files in the test directory and
3501 start and test an https server instead.)
3502     </p>
3504     <clix:function name="hunchentoot-test:test-hunchentoot">
3505       <clix:lambda-list>base-url <clix:lkw>key</clix:lkw></clix:lambda-list>
3506       <clix:returns>|</clix:returns>
3507       <clix:description>
3508         Runs the built-in confidence
3509         test.  <clix:arg>base-url</clix:arg> is the base URL to use
3510         for testing, it should not have a trailing slash.  The keyword
3511         arguments accepted are for future extension and should not
3512         currently be used.
3513         <p>
3514           The script expects the Hunchentoot example test server to be
3515           running at the given <clix:arg>base-url</clix:arg> and
3516           retrieves various pages from that server, expecting certain
3517           responses.
3518         </p>
3519       </clix:description>
3520     </clix:function>
3521   </clix:chapter>
3523   <clix:chapter name="debugging" title="Debugging">
3524     By default, Hunchentoot intercepts all errors that occur while
3525     executing request handlers, logs them to the log file and displays
3526     a static error page to the user.  While developing applications,
3527     you may want to change that behavior so that the debugger is
3528     invoked when an error occurs.  You can set
3529     the <clix:ref>*CATCH-ERRORS-P*</clix:ref> to <code>NIL</code> to
3530     make that happen.  Alternatively, you may want to have Hunchentoot
3531     display detailed error information in the error response page.
3532     You can set the <clix:ref>*SHOW-LISP-ERRORS-P*</clix:ref> to a
3533     true value to make that happen.  If you don't want to see Lisp
3534     backtraces in these error pages, you can
3535     set <clix:ref>*SHOW-LISP-BACKTRACES-P*</clix:ref>
3536     to <code>NIL</code>.
3537   </clix:chapter>
3539   <clix:chapter name="history" title="History">
3541     Hunchentoot's predecessor <a href="http://weitz.de/tbnl/">TBNL</a>
3542     (which is short for "To Be Named Later") grew over the years as a
3543     toolkit that I used for various commercial and private
3544     projects. In August 2003, Daniel Barlow started
3545     a <a href="http://article.gmane.org/gmane.lisp.web/148">review of
3546       web APIs</a> on
3547     the <a href="http://www.red-bean.com/lispweb/">lispweb</a> mailing
3548     list and
3549     I <a href="http://article.gmane.org/gmane.lisp.web/153">described</a>
3550     the API of my hitherto-unreleased bunch of code (and christened it
3551     "TBNL").
3552     <p>
3553       It turned out that
3554       <a href="http://www.jeffcaldwell.com/">Jeff Caldwell</a> had
3555       worked on something similar so he emailed me and proposed to
3556       join our efforts. As I had no immediate plans to release my code
3557       (which was poorly organized, undocumented, and mostly
3558       CMUCL-specific), I gave it to Jeff and he worked towards a
3559       release. He added docstrings, refactored, added some stuff, and
3560       based it on KMRCL to make it portable across several Lisp
3561       implementations.
3562     </p>
3563     <p>
3564       Unfortunately, Jeff is at least as busy as I am so he didn't
3565       find the time to finish a full release.  But in spring 2004 I
3566       needed a documented version of the code for a client of mine who
3567       thought it would be good if the toolkit were publicly available
3568       under an open source license. So I took Jeff's code, refactored
3569       again (to sync with the changes I had done in the meantime), and
3570       added documentation.  This resulted in TBNL 0.1.0 (which
3571       initially required mod_lisp as its front-end).
3572     </p>
3573     <p>
3574       In March 2005, Bob Hutchinson sent patches which enabled TBNL to
3575       use other front-ends than mod_lisp.  This made me aware that
3576       TBNL was already <em>almost</em> a full web server, so
3577       eventually I wrote Hunchentoot which <em>was</em> a full web
3578       server, implemented as a wrapper around TBNL.  Hunchentoot 0.1.0
3579       was released at the end of 2005 and was originally
3580       LispWorks-only.
3581     </p>
3582     <p>
3583       Hunchentoot 0.4.0, released in October 2006, was the first
3584       release which also worked with other Common Lisp
3585       implementations.  It is a major rewrite and also incorporates
3586       most of TBNL and replaces it completely.
3587     </p>
3588     <p>
3589       Hunchentoot 1.0.0, released in February 2009, is again a major
3590       rewrite and should be considered work in progress.  It moved to
3591       using
3592       the <a href="http://common-lisp.net/project/usocket/">usocket</a>
3593       and <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux
3594       Threads</a> libraries for non-LispWorks Lisps, thereby removing most of
3595       the platform dependent code.  Threading behaviour was made
3596       controllable through the introduction of
3597       taskmasters.  <a href="http://www.cliki.net/mod_lisp">mod_lisp</a>
3598       support and several other things were removed in this release to
3599       simplify the code base (and partly due to the lack of interest).
3600       Several architectural changes (lots of them not
3601       backwards-compatible) were made to ease customization of
3602       Hunchentoot's behaviour.  A significant part of the 1.0.0
3603       redesign was done
3604       by <a href="http://netzhansa.blogspot.com/">Hans Hübner</a>.
3605     </p>
3606   </clix:chapter>
3608   <clix:chapter name="index" title="Symbol index">
3610     Here are all exported symbols of the <code>HUNCHENTOOT</code>
3611     package in alphabetical order linked to their corresponding
3612     documentation entries:
3614     <clix:index/>
3616   </clix:chapter>
3618   <clix:chapter name="ack" title="Acknowledgements">
3620     Thanks to Jeff Caldwell - TBNL would not have been released
3621     without his efforts.  Thanks
3622     to <a href="http://www.cliki.net/Stefan%20Scholl">Stefan
3623     Scholl</a> and Travis Cross for various additions and fixes to
3624     TBNL, to <a href="http://www.foldr.org/~michaelw/">Michael
3625     Weber</a> for initial file upload code, and
3626     to <a href="http://www.ltn.lv/~jonis/">Janis Dzerins</a> for
3627     his <a href="http://common-lisp.net/project/rfc2388/">RFC 2388
3628     code</a>. Thanks to Bob Hutchison for his code for multiple
3629     front-ends (which made me realize that TBNL was already pretty
3630     close to a "real" web server) and the initial UTF-8 example.
3631     Thanks to <a href="http://netzhansa.blogspot.com/">Hans Hübner</a>
3632     for a lot of architectural and implementation enhancements for the
3633     1.0.0 release and also for transferring the documentation to sane
3634     XHTML.  Thanks to John
3635     Foderaro's <a href="http://opensource.franz.com/aserve/index.html">AllegroServe</a>
3636     for inspiration.  Thanks to <a href="http://www.htg1.de/">Uwe von
3637     Loh</a> for
3638     the <a href="http://www.htg1.de/hunchentoot/hunchentoot.html">Hunchentoot
3639     logo</a>.
3641     <p>
3642       Hunchentoot originally used code
3643       from <a href="http://www.cliki.net/ACL-COMPAT">ACL-COMPAT</a>,
3644       specifically the chunking code from Jochen Schmidt.  (This has been
3645       replaced by <a href="http://weitz.de/chunga/">Chunga</a>.)  When I ported
3646       Hunchentoot to other Lisps than LispWorks, I stole code from
3647       ACL-COMPAT, <a href="http://www.cliki.net/kmrcl">KMRCL</a>,
3648       and <a href="http://www.cliki.net/trivial-sockets">trivial-sockets</a> for
3649       implementation-dependent stuff like sockets and MP.  (This has been replaced by
3650       <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux
3651       Threads</a>
3652       and <a href="http://common-lisp.net/project/usocket/">usocket</a>.)
3653     </p>
3654     <p>
3655       Parts of this documentation were prepared
3656       with <a href="http://weitz.de/documentation-template/">DOCUMENTATION-TEMPLATE</a>,
3657       no animals were harmed.
3658     </p>
3659   </clix:chapter>
3660   <p>
3661     <a href='http://weitz.de/index.html'>BACK TO MY HOMEPAGE
3662     </a>
3663   </p>
3664 </clix:documentation>