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 fully-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>
13 <a href="http://www.htg1.de/hunchentoot/hunchentoot.html"
14 title="Click here for the Hunchentoot logo"
16 <img align="top" width="93" height="45" border="0" src="hunchentoot.gif" />
18 HUNCHENTOOT - The Common Lisp web server formerly known as TBNL
22 <clix:chapter name='abstract' title='Abstract'>
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.
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>.
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
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.
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>.
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>.
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
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),
94 David Lichteblau's <a href="http://common-lisp.net/project/cl-plus-ssl/">CL+SSL</a>
95 (unless you're using LispWorks),
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/">
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>).
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.
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
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
125 Hunchentoot itself together with this documentation can be
127 <a href="http://weitz.de/files/hunchentoot.tar.gz">http://weitz.de/files/hunchentoot.tar.gz</a>.
128 The current version is 1.2.5.
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.
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.
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.
152 Luís Oliveira maintains an
153 unofficial <a href="http://darcs.net/">darcs</a> repository of
155 <a href="http://common-lisp.net/~loliveira/ediware/">http://common-lisp.net/~loliveira/ediware/</a>.
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.
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.
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
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
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).
212 If you want to send patches, please
213 <a href="http://weitz.de/patches.html">read this first</a>.
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
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>.
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.
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
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>" .
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.
278 <clix:chapter name="tutorials" title="Tutorials and add-ons">
280 Here are some Hunchentoot tutorials done by others:
284 <a href="http://www.adampetersen.se/articles/lispweb.htm">"Lisp for the Web"</a> by Adam Petersen.
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.
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>.)
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>.
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.
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.
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.)
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
321 also <a href="http://bc.tech.coop/blog/061013.html">http://bc.tech.coop/blog/061013.html</a>.
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.
334 Here is some software which extends Hunchentoot or is based on it:
337 <li>Tomo Matsumoto's web application
338 framework <a href="http://web4r.org/en/">web4r</a>.
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.
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.
352 href="http://martin-loetzsch.de/ht-simple-ajax/">HT-SIMPLE-AJAX</a>
353 is a simplified version of HT-AJAX.
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>
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.
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.
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.
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.
382 <a href="http://restas.lisper.ru/">RESTAS</a> is a web
383 framework based on Hunchentoot.
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'>
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't want to listen
404 on the default http port 80. There are other initargs most
405 of which you probably won't need very often. They are
406 explained in detail in the docstrings of the slot
407 definitions for this class.
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.
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
428 The default port for <clix:ref>SSL-ACCEPTOR</clix:ref> instances is 443 instead of 80
433 <clix:function generic='true' name='start'>
434 <clix:lambda-list>acceptor
436 <clix:returns>acceptor
438 <clix:description>Starts <clix:arg>acceptor</clix:arg> so that it begins accepting
439 connections. Returns the acceptor.
443 <clix:function generic='true' name='stop'>
444 <clix:lambda-list>acceptor &key soft</clix:lambda-list>
445 <clix:returns>acceptor
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
458 <clix:special-variable name='*acceptor*'>
459 <clix:description>The current ACCEPTOR object in the context of a request.
461 </clix:special-variable>
463 <clix:function generic='true' name='listen-backlog'>
464 <clix:lambda-list>listen-backlog
466 <clix:returns>number-of-pending-connections
469 Number of pending connections allowed in the listen socket
470 before the kernel rejects further incoming connections.
475 <clix:readers generic='true'>
476 <clix:listed-reader generic='true' name='acceptor-address'>
477 <clix:lambda-list>acceptor
479 <clix:returns>address
481 </clix:listed-reader>
483 <clix:listed-reader generic='true' name='acceptor-port'>
484 <clix:lambda-list>acceptor
488 </clix:listed-reader>
490 <clix:listed-reader generic='true' name='acceptor-read-timeout'>
491 <clix:lambda-list>acceptor
493 <clix:returns>read-timeout
495 </clix:listed-reader>
497 <clix:listed-reader generic='true' name='acceptor-ssl-certificate-file'>
498 <clix:lambda-list>ssl-acceptor
500 <clix:returns>ssl-certificate-file
502 </clix:listed-reader>
504 <clix:listed-reader generic='true' name='acceptor-ssl-privatekey-file'>
505 <clix:lambda-list>ssl-acceptor
507 <clix:returns>ssl-privatekey-file
509 </clix:listed-reader>
511 <clix:listed-reader generic='true' name='acceptor-ssl-privatekey-password'>
512 <clix:lambda-list>ssl-acceptor
514 <clix:returns>ssl-privatekey-password
516 </clix:listed-reader>
518 <clix:listed-reader generic='true' name='acceptor-write-timeout'>
519 <clix:lambda-list>acceptor
521 <clix:returns>write-timeout
523 </clix:listed-reader>
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.
534 <clix:accessors generic='true'>
535 <clix:listed-accessor generic='true' name='acceptor-access-log-destination'>
536 <clix:lambda-list>acceptor
538 <clix:returns>(or pathname null)
540 </clix:listed-accessor>
542 <clix:listed-accessor generic='true' name='acceptor-document-root'>
543 <clix:lambda-list>acceptor
545 <clix:returns>(or pathname null)
547 </clix:listed-accessor>
549 <clix:listed-accessor generic='true' name='acceptor-error-template-directory'>
550 <clix:lambda-list>acceptor
552 <clix:returns>(or pathname null)
554 </clix:listed-accessor>
556 <clix:listed-accessor generic='true' name='acceptor-input-chunking-p'>
557 <clix:lambda-list>acceptor
559 <clix:returns>input-chunking-p
561 </clix:listed-accessor>
563 <clix:listed-accessor generic='true' name='acceptor-message-log-destination'>
564 <clix:lambda-list>acceptor
566 <clix:returns>(or pathname null)
568 </clix:listed-accessor>
570 <clix:listed-accessor generic='true' name='acceptor-name'>
571 <clix:lambda-list>acceptor
575 </clix:listed-accessor>
577 <clix:listed-accessor generic='true' name='acceptor-output-chunking-p'>
578 <clix:lambda-list>acceptor
580 <clix:returns>output-chunking-p
582 </clix:listed-accessor>
584 <clix:listed-accessor generic='true' name='acceptor-persistent-connections-p'>
585 <clix:lambda-list>acceptor
587 <clix:returns>persistent-connections-p
589 </clix:listed-accessor>
591 <clix:listed-accessor generic='true' name='acceptor-reply-class'>
592 <clix:lambda-list>acceptor
594 <clix:returns>reply-class
596 </clix:listed-accessor>
598 <clix:listed-accessor generic='true' name='acceptor-request-class'>
599 <clix:lambda-list>acceptor
601 <clix:returns>request-class
603 </clix:listed-accessor>
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.
612 <clix:function generic='true' name='acceptor-ssl-p'>
613 <clix:lambda-list>acceptor
615 <clix:returns>generalized-boolean
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're using secure connections - see the <clix:ref>SSL-ACCEPTOR</clix:ref> class.
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>.
631 </clix:special-variable>
633 <clix:function generic='true' name='acceptor-remove-session'>
634 <clix:lambda-list>acceptor session
636 <clix:returns>generalized-boolean
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.
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>.
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.
679 <clix:function generic='true' name='start-listening'>
680 <clix:lambda-list>acceptor
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 'address in use'
692 <clix:function generic='true' name='accept-connections'>
693 <clix:lambda-list>acceptor
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.
705 <clix:function generic='true' name='process-connection'>
706 <clix:lambda-list>acceptor socket
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.
728 <clix:function generic='true' name='initialize-connection-stream'>
729 <clix:lambda-list>acceptor stream
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.
743 <clix:function generic='true' name='reset-connection-stream'>
744 <clix:lambda-list>acceptor stream
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
757 <clix:function name="acceptor-log-access" generic="true">
758 <clix:lambda-list>acceptor &key return-code</clix:lambda-list>
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.
768 <clix:function name="acceptor-log-message" generic="true">
769 <clix:lambda-list>acceptor log-level format-string &rest format-arguments</clix:lambda-list>
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
778 <clix:function name="acceptor-status-message" generic="true">
779 <clix:lambda-list>acceptor http-return-code content</clix:lambda-list>
781 This function is called after the request's handler has been
782 invoked to convert the <clix:arg>HTTP-STATUS-CODE</clix:arg>
783 to a HTML message to be displayed to the user. If this
784 function returns a string, that string is sent to the client
785 instead of the content produced by the handler, if any.
787 If an ERROR-TEMPLATE-DIRECTORY is set in the current
788 acceptor and the directory contains a file corresponding to
789 HTTP-STATUS-CODE named <code>.html, that file is sent
790 to the client after variable substitution. Variables are
791 referenced by ${<variable-name>}.
793 Additional keyword arguments may be provided which are made
794 available to the templating logic as substitution variables.
795 These variables can be interpolated into error message
796 templates in, which contains the current URL relative to the
797 server and without GET parameters.
799 In addition to the variables corresponding to keyword
800 arguments, the script-name, lisp-implementation-type,
801 lisp-implementation-version and hunchentoot-version
802 variables are available.
807 <clix:subchapter name="subclassing-acceptors"
808 title="An example of how to subclass ACCEPTOR">
810 This example shows how to subclass <clix:ref>ACCEPTOR</clix:ref> in order to
811 provide Hunchentoot with basic virtual host support.  It assumes
812 Hunchentoot is sitting behind an Internet-facing reverse-proxy web server
813 that maps the host (or domain) part of incoming HTTP requests to unique
816 <pre>(asdf:load-system "hunchentoot")
817 (asdf:load-system "drakma")
819 ;;; Subclass ACCEPTOR
820 (defclass vhost (tbnl:acceptor)
824 :accessor dispatch-table
825 :documentation "List of dispatch functions"))
827 (:default-initargs ; default-initargs must be used
828 :address "127.0.0.1")) ; because ACCEPTOR uses it
830 ;;; Specialise ACCEPTOR-DISPATCH-REQUEST for VHOSTs
831 (defmethod tbnl:acceptor-dispatch-request ((vhost vhost) request)
832 ;; try REQUEST on each dispatcher in turn
833 (mapc (lambda (dispatcher)
834 (let ((handler (funcall dispatcher request)))
835 (when handler ; Handler found. FUNCALL it and return result
836 (return-from tbnl:acceptor-dispatch-request (funcall handler)))))
837 (dispatch-table vhost))
840 ;;; ======================================================================
841 ;;; Now all we need to do is test it
843 ;;; Instantiate VHOSTs
844 (defvar vhost1 (make-instance 'vhost :port 50001))
845 (defvar vhost2 (make-instance 'vhost :port 50002))
847 ;;; Populate each dispatch table
849 (tbnl:create-prefix-dispatcher "/foo" 'foo1)
850 (dispatch-table vhost1))
852 (tbnl:create-prefix-dispatcher "/foo" 'foo2)
853 (dispatch-table vhost2))
856 (defun foo1 () "Hello")
857 (defun foo2 () "Goodbye")
863 ;;; Make some requests
864 (drakma:http-request "http://127.0.0.1:50001/foo")
866 ;;; 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/)"
870 ;;; ((:CONTENT-LENGTH . "5") (:DATE . "Fri, 08 Jun 2012 14:30:39 GMT")
871 ;;; (:SERVER . "Hunchentoot 1.2.3") (:CONNECTION . "Close")
872 ;;; (:CONTENT-TYPE . "text/html; charset=utf-8"))
873 ;;; #<PURI:URI http://127.0.0.1:50001/foo>
874 ;;; #<FLEXI-STREAMS:FLEXI-IO-STREAM {CA90059}>
877 (drakma:http-request "http://127.0.0.1:50002/foo")
879 ;;; 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/)"
883 ;;; ((:CONTENT-LENGTH . "7") (:DATE . "Fri, 08 Jun 2012 14:30:47 GMT")
884 ;;; (:SERVER . "Hunchentoot 1.2.3") (:CONNECTION . "Close")
885 ;;; (:CONTENT-TYPE . "text/html; charset=utf-8"))
886 ;;; #<PURI:URI http://127.0.0.1:50002/foo>
887 ;;; #<FLEXI-STREAMS:FLEXI-IO-STREAM {CAE8059}>
891 How to make each VHOST write to separate access log streams (or files) is
892 left as an exercise to the reader.
896 <clix:subchapter name="taskmasters" title="Taskmasters">
897 As a "normal" Hunchentoot user, you can completely ignore
898 taskmasters and skip this section. But if you're still reading,
899 here are the dirty details: Each <a
900 href="#acceptors">acceptor</a> has a taskmaster associated with
901 it at creation time. It is the taskmaster's job to distribute
902 the work of accepting and handling incoming connections. The
903 acceptor calls the taskmaster if appropriate and the taskmaster
904 calls back into the acceptor. This is done using the generic
905 functions described in this and the <a
906 href="#acceptor-behaviour">previous</a> section. Hunchentoot
907 comes with two standard taskmaster implementations - one (which
908 is the default used on multi-threaded Lisps) which starts a new
909 thread for each incoming connection and one which handles all
910 requests sequentially. It should for example be relatively
911 straightforward to create a taskmaster which allocates threads
912 from a fixed pool instead of creating a new one for each
916 You can control the resources consumed by a threaded taskmaster via
917 two initargs. <code>:max-thread-count</code> lets you set the maximum
918 number of request threads that can be processes simultaneously. If
919 this is <code>nil</code>, the is no thread limit imposed.
921 <code>:max-accept-count</code> lets you set the maximum number of requests
922 that can be outstanding (i.e. being processed or queued for processing).
924 If <code>:max-thread-count</code> is supplied and <code>:max-accept-count</code>
925 is <code>NIL</code>, then a <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>
926 error will be generated if there are more than the max-thread-count
927 threads processing requests. If both <code>:max-thread-count</code>
928 and <code>:max-accept-count</code> are supplied, then max-thread-count
929 must be less than max-accept-count; if more than max-thread-count
930 requests are being processed, then requests up to max-accept-count
931 will be queued until a thread becomes available. If more than
932 max-accept-count requests are outstanding, then a <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>
933 error will be generated.
935 In a load-balanced environment with multiple Hunchentoot servers, it's
936 reasonable to provide <code>:max-thread-count</code> but leave
937 <code>:max-accept-count</code> null. This will immediately result
938 in <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref> when one server is
939 out of resources, so the load balancer can try to find another server.
941 In an environment with a single Hunchentoot server, it's reasonable
942 to provide both <code>:max-thread-count</code> and a somewhat larger value
943 for <code>:max-accept-count</code>. This will cause a server that's almost
944 out of resources to wait a bit; if the server is completely out of resources,
945 then the reply will be <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref>.
946 The default for these values is 100 and 120, respectively.
950 If you want to implement your own taskmasters, you should subclass
951 <clix:ref>TASKMASTER</clix:ref> or one of its subclasses,
952 <clix:ref>SINGLE-THREADED-TASKMASTER</clix:ref> or
953 <clix:ref>ONE-THREAD-PER-CONNECTION-TASKMASTER</clix:ref>, and
954 specialize the generic functions in this section.
957 <clix:class name='taskmaster'>
959 An instance of this class is responsible for distributing
960 the work of handling requests for its acceptor. This is an
961 "abstract" class in the sense that usually only instances of
962 subclasses of <clix:ref>TASKMASTER</clix:ref> will be used.
966 <clix:class name='one-thread-per-connection-taskmaster'>
968 A taskmaster that starts one thread for listening to
969 incoming requests and one thread for each incoming
972 This is the default taskmaster implementation for multi-threaded Lisp
978 <clix:class name='single-threaded-taskmaster'>
980 A taskmaster that runs synchronously in the
981 thread where the <clix:ref>START</clix:ref> function was invoked (or
982 in the case of LispWorks in the thread started
983 by <a href="http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-61.htm#marker-910861"><code>COMM:START-UP-SERVER</code></a>).
984 This is the simplest possible taskmaster implementation in that its
985 methods do nothing but calling their acceptor "sister"
986 methods - <clix:ref>EXECUTE-ACCEPTOR</clix:ref> calls <clix:ref>ACCEPT-CONNECTIONS</clix:ref>,
987 <clix:ref>HANDLE-INCOMING-CONNECTION</clix:ref> calls <clix:ref>PROCESS-CONNECTION</clix:ref>.
991 <clix:function generic='true' name='execute-acceptor'>
992 <clix:lambda-list>taskmaster
996 <clix:description>This is a callback called by the acceptor once it
997 has performed all initial processing to start listening for incoming
998 connections (see <clix:ref>START-LISTENING</clix:ref>). It usually calls the
999 <clix:ref>ACCEPT-CONNECTIONS</clix:ref> method of the acceptor, but depending on the
1000 taskmaster instance the method might be called from a new thread.
1004 <clix:function generic='true' name='handle-incoming-connection'>
1005 <clix:lambda-list>taskmaster socket
1007 <clix:returns>result
1010 This function is called by the acceptor to start
1011 processing of requests on a new incoming connection. <clix:arg>socket</clix:arg> is the
1012 usocket instance that represents the new connection (or a socket
1013 handle on LispWorks). The taskmaster starts processing requests on
1014 the incoming connection by calling the <clix:ref>PROCESS-CONNECTION</clix:ref>
1015 method of the acceptor instance. The <clix:arg>socket</clix:arg> argument is passed to
1016 <clix:ref>PROCESS-CONNECTION</clix:ref> as an argument.
1018 If the taskmaster is a multi-threaded taskmaster, <clix:ref>HANDLE-INCOMING-THREAD</clix:ref>
1019 will call <clix:ref>CREATE-TASKMASTER-THREAD</clix:ref>, which will call
1020 <clix:ref>PROCESS-CONNECTION</clix:ref> in a new thread.
1021 <clix:ref>HANDLE-INCOMING-THREAD</clix:ref> might issue a
1022 <clix:ref>+HTTP-SERVICE-UNAVAILABLE+</clix:ref> error
1023 if there are too many request threads or it might block waiting for a
1024 request thread to finish.
1028 <clix:function generic='true' name='create-taskmaster-thread'>
1029 <clix:lambda-list>taskmaster socket
1031 <clix:returns>thread
1033 <clix:description>This function is called by <clix:ref>HANDLE-INCOMING-THREAD</clix:ref>
1034 to create a new thread which calls <clix:ref>PROCESS-CONNECTION</clix:ref>.
1035 If you specialize this function, you must be careful to have the thread
1036 call <clix:ref>DECREMENT-TASKMASTER-REQUEST-COUNT</clix:ref> before
1037 it exits. A typical method will look like this:
1039 <pre>(defmethod create-taskmaster-thread ((taskmaster monitor-taskmaster) socket)
1042 (with-monitor-error-handlers
1044 (with-monitor-variable-bindings
1045 (process-connection (taskmaster-acceptor taskmaster) socket))
1046 (decrement-taskmaster-request-count taskmaster))))))</pre>
1057 <clix:function generic='true' name='shutdown'>
1058 <clix:lambda-list>taskmaster
1060 <clix:returns>taskmaster
1062 <clix:description>Shuts down the taskmaster, i.e. frees all resources
1063 that were set up by it. For example, a multi-threaded taskmaster
1064 might terminate all threads that are currently associated with it.
1065 This function is called by the acceptor's <clix:ref>STOP</clix:ref> method.
1069 <clix:accessor generic='true' name='taskmaster-acceptor'>
1070 <clix:lambda-list>taskmaster
1072 <clix:returns>acceptor
1075 This is an accessor for the slot of a <clix:ref>TASKMASTER</clix:ref>
1076 object that links back to the <a href="#acceptors">acceptor</a> it is
1083 <clix:subchapter name="request-dispatch" title="Request dispatch and handling">
1085 The main job of <clix:ref>HANDLE-REQUEST</clix:ref> is to select
1086 and call a function which handles the request, i.e. which looks
1087 at the data the client has sent and prepares an appropriate
1088 reply to send back. This is by default implemented as follows:
1090 The ACCEPTOR class defines a
1091 <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> generic
1092 function which is used to actually dispatch the request. This
1093 function is called by the default method of
1094 <clix:ref>HANDLE-REQUEST</clix:ref>. Each
1095 <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> method looks at
1096 the request object and depending on its contents decides to
1097 either handle the request or call the next method.
1100 In order to dispatch a request, Hunchentoot calls the
1101 <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> generic
1102 functions. The method for <clix:ref>ACCEPTOR</clix:ref> tries
1103 to serve a static file relative to it's
1104 <clix:ref>ACCEPTOR-DOCUMENT-ROOT</clix:ref>. Application
1105 specific acceptor subclasses will typically perform URL
1106 parsing and dispatching according to the policy that is
1110 The default method of <clix:ref>HANDLE-REQUEST</clix:ref> sets
1111 up <a href="#logging">standard logging and error handling</a>
1112 before it calls the acceptor's request dispatcher.
1115 Request handlers do their work by modifying
1116 the <a href="#replies">reply object</a> if necessary and by eventually
1117 returning the response body in the form of a string or a binary
1118 sequence. As an alternative, they can also
1119 call <clix:ref>SEND-HEADERS</clix:ref> and write directly to a stream.
1123 <clix:subchapter name="easy-handlers" title="Using the easy-handler framework">
1125 The <clix:ref>EASY-ACCEPTOR</clix:ref> class defines a method
1126 for <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> that walks
1127 through the list <clix:ref>*DISPATCH-TABLE*</clix:ref> which
1128 consists of <em>dispatch functions</em>. Each of these
1129 functions accepts the request object as its only argument and
1130 either returns a request handler to handle the request or
1131 <code>NIL</code> which means that the next dispatcher in the
1132 list will be tried. If all dispatch functions return
1133 <code>NIL</code>, the next
1134 <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref> will be called.
1137 All functions and variables in this section are related to the
1138 easy request dispatch mechanism and are meaningless if you're
1139 using your own request dispatcher.
1142 <clix:class name='easy-acceptor'>
1144 This class defines no additional slots with respect to
1145 <clix:ref>ACCEPTOR</clix:ref>. It only serves as an
1146 additional type for dispatching calls to
1147 <clix:ref>ACCEPTOR-DISPATCH-REQUEST</clix:ref>. In order to
1148 use the easy handler framework, acceptors of this class or
1149 one of its subclasses must be used.
1153 <clix:class name='easy-ssl-acceptor'>
1155 This class mixes the <clix:ref>SSL-ACCEPTOR</clix:ref> and
1156 the <clix:ref>EASY-ACCEPTOR</clix:ref> classes. It is used
1157 when both ssl and the easy handler framework are required.
1161 <clix:special-variable name='*dispatch-table*'>
1163 A global list of dispatch functions. The initial value is a
1164 list consisting of the symbol
1165 <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>.
1167 </clix:special-variable>
1169 <clix:function name="create-prefix-dispatcher">
1170 <clix:lambda-list>prefix handler</clix:lambda-list>
1171 <clix:returns>dispatch-fn</clix:returns>
1173 A convenience function which will return a dispatcher that
1174 returns <clix:arg>handler</clix:arg> whenever the path part of
1175 the request URI starts with the
1176 string <clix:arg>prefix</clix:arg>.
1180 <clix:function name="create-regex-dispatcher">
1181 <clix:lambda-list>regex handler</clix:lambda-list>
1182 <clix:returns>dispatch-fn</clix:returns>
1184 A convenience function which will return a dispatcher that
1185 returns <clix:arg>handler</clix:arg> whenever the path part of
1186 the request URI matches
1187 the <a href="http://weitz.de/cl-ppcre/">CL-PPCRE</a> regular
1188 expression <clix:arg>regex</clix:arg> (which can be a string, an
1189 s-expression, or a scanner).
1193 <clix:function name="create-folder-dispatcher-and-handler">
1194 <clix:lambda-list>uri-prefix base-path <clix:lkw>optional</clix:lkw> content-type</clix:lambda-list>
1195 <clix:returns>dispatch-fn</clix:returns>
1197 Creates and returns a dispatch function which will dispatch to
1198 a handler function which emits the file relative
1199 to <clix:arg>base-path</clix:arg> that is denoted by the URI of
1200 the request relative
1201 to <clix:arg>uri-prefix</clix:arg>. <clix:arg>uri-prefix</clix:arg>
1202 must be a string ending with a
1203 slash, <clix:arg>base-path</clix:arg> must be a pathname
1204 designator for an existing directory.
1205 Uses <clix:ref>HANDLE-STATIC-FILE</clix:ref> internally.
1207 If <clix:arg>content-type</clix:arg> is <em>not</em>
1208 <code>NIL</code>, it will be used as a the content type for
1209 all files in the folder. Otherwise (which is the default)
1210 the content type of each file will be
1211 determined <a href="#handle-static-file">as usual</a>.
1216 <clix:function name='create-static-file-dispatcher-and-handler'>
1217 <clix:lambda-list>uri path
1219 </clix:lkw> content-type
1221 <clix:returns>result
1224 Creates and returns a request dispatch function which will
1225 dispatch to a handler function which emits the file denoted
1226 by the pathname designator PATH with content type
1227 CONTENT-TYPE if the SCRIPT-NAME of the request matches the
1228 string URI. If CONTENT-TYPE is NIL, tries to determine the
1229 content type via the file's suffix.
1233 <clix:function macro="true" name="define-easy-handler">
1234 <clix:lambda-list>description lambda-list [[declaration* | documentation]] form*</clix:lambda-list>
1236 Defines a handler as if
1237 by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/m_defun.htm">
1238 <code>DEFUN</code></a> and optionally registers it with a
1239 URI so that it will be found
1240 by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>.
1242 <clix:arg>description</clix:arg> is either a
1243 symbol <clix:arg>name</clix:arg> or a list matching the
1244 <a href="http://www.lispworks.com/documentation/HyperSpec/Body/03_de.htm">destructuring
1247 <pre>(name &key uri acceptor-names default-parameter-type default-request-type).</pre>
1248 <clix:arg>lambda-list</clix:arg> is a list the elements of which
1249 are either a symbol <clix:arg>var</clix:arg> or a list matching
1250 the destructuring lambda list
1251 <pre>(var &key real-name parameter-type init-form request-type).</pre>
1252 The resulting handler will be a Lisp function with the
1253 name <clix:arg>name</clix:arg> and keyword parameters named by
1254 the <clix:arg>var</clix:arg> symbols.
1255 Each <clix:arg>var</clix:arg> will be bound to the value of the
1256 GET or POST parameter called <clix:arg>real-name</clix:arg> (a
1257 string) before the body of the function is executed.
1258 If <clix:arg>real-name</clix:arg> is not provided, it will be
1260 by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stg_up.htm#string-downcase">downcasing</a>
1261 the symbol name of <clix:arg>var</clix:arg>.
1263 If <clix:arg>uri</clix:arg> (which is evaluated) is provided,
1264 then it must be a string or
1265 a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_designator">function
1266 designator</a> for a unary function. In this case, the
1267 handler will be returned
1268 by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>,
1269 if <clix:arg>uri</clix:arg> is a string and
1270 the <a href="#script-name">script name</a> of the current
1271 request is <clix:arg>uri</clix:arg>, or
1272 if <clix:arg>uri</clix:arg> designates a function and applying
1274 the <a href="#*request*">current <code>REQUEST</code>
1275 object</a> returns a true value.
1278 <clix:arg>acceptor-names</clix:arg> (which is evaluated) can be a
1279 list of symbols which means that the handler will only be
1280 returned by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref> in
1281 acceptors which have one of these names
1282 (see <clix:ref>ACCEPTOR-NAME</clix:ref>). <clix:arg>acceptor-names</clix:arg> can also be the
1283 symbol <code>T</code> which means that the handler will be
1284 returned by <clix:ref>DISPATCH-EASY-HANDLERS</clix:ref>
1285 in <em>every</em> acceptor.
1288 Whether the GET or POST parameter (or both) will be taken into
1289 consideration, depends on <clix:arg>request-type</clix:arg>
1291 be <code>:GET</code>, <code>:POST</code>, <code>:BOTH</code>,
1292 or <code>NIL</code>. In the last case, the value of
1293 <clix:arg>default-request-type</clix:arg> (the default of which
1294 is <code>:BOTH</code>) will be used.
1297 The value of <clix:arg>var</clix:arg> will usually be a string
1298 (unless it resulted from a <a href="#upload">file upload</a>
1299 in which case it won't be converted at all), but
1300 if <clix:arg>parameter-type</clix:arg> (which is evaluated) is
1301 provided, the string will be converted to another Lisp type by
1302 the following rules:
1305 If the corresponding GET or POST parameter wasn't provided by
1306 the client, <clix:arg>var</clix:arg>'s value will
1307 be <code>NIL</code>. If <clix:arg>parameter-type</clix:arg>
1308 is <code>'STRING</code>,
1309 <clix:arg>var</clix:arg>'s value remains as is.
1310 If <clix:arg>parameter-type</clix:arg> is <code>'INTEGER</code>
1311 and the parameter string consists solely of decimal
1312 digits, <clix:arg>var</clix:arg>'s value will be the
1313 corresponding integer, otherwise <code>NIL</code>.
1314 If <clix:arg>parameter-type</clix:arg> is
1315 <code>'KEYWORD</code>, <clix:arg>var</clix:arg>'s value will be
1316 the keyword obtained
1317 by <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_intern.htm">interning</a>
1318 the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/f_stg_up.htm#string-upcase">upcased</a>
1319 parameter string into
1320 the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/11_abc.htm">keyword
1321 package</a>. If <clix:arg>parameter-type</clix:arg>
1322 is <code>'CHARACTER</code> and the parameter string is of
1323 length one, <clix:arg>var</clix:arg>'s value will be the single
1324 character of this string, otherwise <code>NIL</code>.
1325 If <clix:arg>parameter-type</clix:arg>
1326 is <code>'BOOLEAN</code>, <clix:arg>var</clix:arg>'s value will
1327 always be <code>T</code> (unless it is <code>NIL</code> by the
1328 first rule above, of course).
1329 If <clix:arg>parameter-type</clix:arg> is any other atom, it is
1331 a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_f.htm#function_designator">function
1332 designator</a> for a unary function which will be called to
1333 convert the string to something else.
1336 Those were the rules for <em>simple</em> parameter types, but
1337 <clix:arg>parameter-type</clix:arg> can also be a list starting
1338 with one of the symbols
1339 <code>LIST</code>, <code>ARRAY</code>,
1340 or <code>HASH-TABLE</code>. The second value of the list must
1341 always be a simple parameter type as in the last paragraph -
1342 we'll call it the <em>inner type</em> below.
1345 In the case of <code>'LIST</code>, all GET/POST parameters
1346 called <clix:arg>real-name</clix:arg> will be collected,
1347 converted to the inner type as by the rules above, and
1348 assembled into a list which will be the value of
1349 <clix:arg>var</clix:arg>.
1352 In the case of <code>'ARRAY</code>, all GET/POST parameters
1353 which have a name like the result of
1355 <pre>(format nil "~A[~A]" real-name n)</pre>
1356 where <clix:arg>n</clix:arg> is a non-negative integer, will be
1357 assembled into an array where the <clix:arg>n</clix:arg>th element
1358 will be set accordingly, after conversion to the inner type.
1359 The array, which will become the value
1360 of <clix:arg>var</clix:arg>, will be big enough to hold all
1361 matching parameters, but not bigger. Array elements not set as
1362 described above will be <code>NIL</code>. Note
1363 that <code>VAR</code> will always be bound to an array, which
1364 may be empty, so it will never be <code>NIL</code>, even if no
1365 appropriate GET/POST parameters are found.
1367 The full form of a <code>'HASH-TABLE</code> parameter type is
1369 <pre>(hash-table inner-type key-type test-function)</pre>
1370 but <clix:arg>key-type</clix:arg>
1371 and <clix:arg>test-function</clix:arg> can be left out in which
1372 case they default to <code>'STRING</code>
1373 and <code>'EQUAL</code>, respectively. For this parameter type,
1374 all GET/POST parameters which have a name like the result of
1375 <pre>(format nil "~A{~A}" real-name key)</pre>
1376 (where <clix:arg>key</clix:arg> is a string that doesn't contain
1377 curly brackets) will become the values (after conversion
1378 to <clix:arg>inner-type</clix:arg>) of a hash table with test
1379 function <clix:arg>test-function</clix:arg>
1380 where <clix:arg>key</clix:arg> (after conversion
1381 to <clix:arg>key-type</clix:arg>) will be the corresponding key.
1382 Note that <clix:arg>var</clix:arg> will always be bound to a hash
1383 table, which may be empty, so it will never be <code>NIL</code>,
1384 even if no appropriate GET/POST parameters are found.
1386 To make matters even more complicated, the three compound
1387 parameter types also have an abbreviated form - just one of
1388 the symbols <code>LIST</code>, <code>ARRAY</code>,
1389 or <code>HASH-TABLE</code>. In this case, the inner type will
1390 default to <code>'STRING</code>.
1393 If <clix:arg>parameter-type</clix:arg> is not provided
1394 or <code>NIL</code>, <clix:arg>default-parameter-type</clix:arg>
1395 (the default of which is <code>'STRING</code>) will be used
1399 If the result of the computations above would be
1400 that <clix:arg>var</clix:arg> would be bound
1401 to <code>NIL</code>, then <clix:arg>init-form</clix:arg> (if
1402 provided) will be evaluated instead,
1403 and <clix:arg>var</clix:arg> will be bound to the result of this
1407 Handlers built with this macro are constructed in such a way
1408 that the resulting Lisp function is useful even outside of
1409 Hunchentoot. Specifically, all the parameter computations
1410 above will only happen if <clix:ref>*REQUEST*</clix:ref> is
1411 bound, i.e. if we're within a Hunchentoot request.
1412 Otherwise, <clix:arg>var</clix:arg> will always be bound to the
1413 result of evaluating <clix:arg>init-form</clix:arg> unless a
1414 corresponding keyword argument is provided.
1417 The <a href="#example">example code</a> that comes with
1418 Hunchentoot contains an example which demonstrates some of the
1419 features of <clix:ref>DEFINE-EASY-HANDLER</clix:ref>.
1424 <clix:function name='dispatch-easy-handlers'>
1425 <clix:lambda-list>request
1427 <clix:returns>result
1429 <clix:description>This is a dispatcher which returns the appropriate handler
1430 defined with <clix:ref>DEFINE-EASY-HANDLER</clix:ref>, if there is one.
1436 <clix:subchapter name="requests" title="Request objects">
1438 For each incoming request, the <a href="#acceptors">acceptor</a> (in
1439 <clix:ref>PROCESS-CONNECTION</clix:ref>) creates a
1440 <clix:ref>REQUEST</clix:ref> object and makes it available to <a
1441 href="#request-dispatch">handlers</a> via the special variable
1442 <clix:ref>*REQUEST*</clix:ref>. This object contains all relevant
1443 information about the request and this section collects the functions
1444 which can be used to query such an object. In all function where
1445 <clix:arg>request</clix:arg> is an optional or keyword parameter, the
1446 default is <clix:ref>*REQUEST*</clix:ref>.
1449 If you need more fine-grained control over the behaviour of request
1450 objects, you can subclass <clix:ref>REQUEST</clix:ref> and initialize
1451 the <a href="#acceptor-request-class"><code>REQUEST-CLASS</code></a>
1452 slot of the <clix:ref>ACCEPTOR</clix:ref> class accordingly. The
1453 acceptor will generate request objects of the class named by this
1457 <clix:class name='request'>
1459 Objects of this class hold all the information
1460 about an incoming request. They are created automatically by
1461 acceptors and can be accessed by the
1462 corresponding <a href="#request-dispatch">handler</a>.
1464 You should not mess with the slots of these objects directly, but you
1465 can subclass <clix:ref>REQUEST</clix:ref> in order to implement your
1467 the <a href="#acceptor-request-class"><code>REQUEST-CLASS</code></a>
1468 slot of the <clix:ref>ACCEPTOR</clix:ref> class.
1472 <clix:special-variable name='*request*'>
1473 <clix:description>The current REQUEST object while in the context of a request.
1475 </clix:special-variable>
1477 <clix:function name='real-remote-addr'>
1482 <clix:returns>string{, list}
1485 Returns the '<code>X-Forwarded-For</code>' incoming http header as the
1486 second value in the form of a list of IP addresses and the first
1487 element of this list as the first value if this header exists.
1488 Otherwise returns the value of <clix:ref>REMOTE-ADDR</clix:ref> as the only value.
1492 <clix:function name='parameter'>
1493 <clix:lambda-list>name
1497 <clix:returns>string
1500 Returns the GET or the POST parameter with name
1501 <clix:arg>name</clix:arg> (a string) - or <code>NIL</code>
1502 if there is none. If both a GET and a POST parameter with
1503 the same name exist the GET parameter is returned. Search
1504 is case-sensitive. See also
1505 <clix:ref>GET-PARAMETER</clix:ref> and
1506 <clix:ref>POST-PARAMETER</clix:ref>.
1510 <clix:function name="get-parameter">
1511 <clix:lambda-list>name <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1512 <clix:returns>string</clix:returns>
1514 Returns the value of the GET parameter (as provided via the
1515 request URI) named by the string <clix:arg>name</clix:arg> as a
1516 string (or <code>NIL</code> if there ain't no GET parameter
1517 with this name). Note that only the first value will be
1518 returned if the client provided more than one GET parameter
1519 with the name <clix:arg>name</clix:arg>. See
1520 also <clix:ref>GET-PARAMETERS*</clix:ref>.
1524 <clix:function name="post-parameter">
1525 <clix:lambda-list>name <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1526 <clix:returns>string</clix:returns>
1528 Returns the value of the POST parameter (as provided in the
1529 request's body) named by the
1530 string <clix:arg>name</clix:arg>. Note that only the first value
1531 will be returned if the client provided more than one POST
1532 parameter with the name <clix:arg>name</clix:arg>. This value
1533 will usually be a string (or <code>NIL</code> if there ain't
1534 no POST parameter with this name). If, however, the browser
1535 sent a <a class="none" name="upload">file</a> through
1536 a <a href="http://www.faqs.org/rfcs/rfc2388.html">
1537 <code>multipart/form-data</code>
1538 </a> form, the value of this function is a three-element list
1539 <pre>(path file-name content-type)</pre>
1540 where <clix:arg>path</clix:arg> is a pathname denoting the place
1541 were the uploaded file was
1542 stored, <clix:arg>file-name</clix:arg> (a string) is the file
1543 name sent by the browser, and <clix:arg>content-type</clix:arg>
1544 (also a string) is the content type sent by the browser. The
1545 file denoted by <clix:arg>path</clix:arg> will be deleted after
1546 the request has been handled - you have to move or copy it
1547 somewhere else if you want to keep it.
1549 POST parameters will only be computed if the content type of
1550 the request body was <code>multipart/form-data</code>
1551 or <code>application/x-www-form-urlencoded</code>. Although
1552 this function is called <code>POST-PARAMETER</code>, you can
1553 instruct Hunchentoot to compute these parameters for other
1555 setting <clix:ref>*METHODS-FOR-POST-PARAMETERS*</clix:ref>.
1558 See also <clix:ref>POST-PARAMETERS</clix:ref>
1559 and <clix:ref>*TMP-DIRECTORY*</clix:ref>.
1564 <clix:function name="get-parameters*">
1565 <clix:lambda-list><clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1566 <clix:returns>alist</clix:returns>
1569 an <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#alist">alist</a>
1570 of all GET parameters (as provided via the request
1571 URI). The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#car">car</a>
1572 of each element of this list is the parameter's name while
1573 the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#cdr">cdr</a>
1574 is its value (as a string). The elements of this list are in
1575 the same order as they were within the request URI. See
1576 also <clix:ref>GET-PARAMETER</clix:ref>.
1580 <clix:function name="post-parameters*">
1581 <clix:lambda-list><clix:lkw>optional</clix:lkw> request</clix:lambda-list>
1582 <clix:returns>alist</clix:returns>
1585 an <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#alist">alist</a>
1586 of all POST parameters (as provided via the request's
1587 body). The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#car">car</a>
1588 of each element of this list is the parameter's name while
1589 the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_c.htm#cdr">cdr</a>
1590 is its value. The elements of this list are in the same order
1591 as they were within the request's body.
1593 See also <clix:ref>POST-PARAMETER</clix:ref>.
1598 <clix:special-variable name='*methods-for-post-parameters*'>
1599 <clix:description>A list of the request method types (as keywords) for which
1600 Hunchentoot will try to compute <clix:arg>post-parameters</clix:arg>.
1602 </clix:special-variable>
1604 <clix:function name='cookie-in'>
1605 <clix:lambda-list>name
1609 <clix:returns>cookie
1612 Returns the cookie with the name <clix:arg>name</clix:arg> (a string) as sent by the
1613 browser - or <code>NIL</code> if there is none.
1617 <clix:function name='cookies-in*'>
1624 <clix:description>Returns an alist of all cookies associated with the <clix:ref>REQUEST</clix:ref> object
1625 <clix:arg>request</clix:arg>.
1629 <clix:function name='host'>
1636 <clix:description>Returns the 'Host' incoming http header value.
1640 <clix:function name='query-string*'>
1645 <clix:returns>string
1648 Returns the query string of the <clix:ref>REQUEST</clix:ref> object <clix:arg>request</clix:arg>. That's
1649 the part behind the question mark (i.e. the GET parameters).
1653 <clix:function name='referer'>
1658 <clix:returns>result
1661 Returns the 'Referer' (sic!) http header.
1665 <clix:function name='request-method*'>
1670 <clix:returns>keyword
1673 Returns the request method as a Lisp keyword.
1677 <clix:function name='request-uri*'>
1685 Returns the request URI.
1689 <clix:function name='server-protocol*'>
1694 <clix:returns>keyword
1697 Returns the request protocol as a Lisp keyword.
1701 <clix:function name='user-agent'>
1706 <clix:returns>result
1709 Returns the 'User-Agent' http header.
1713 <clix:function name='header-in*'>
1714 <clix:lambda-list>name
1718 <clix:returns>header
1721 Returns the incoming header with name
1722 <clix:arg>name</clix:arg>. <clix:arg>name</clix:arg> can be
1723 a keyword (recommended) or a string.
1727 <clix:function name='headers-in*'>
1735 Returns an alist of the incoming headers associated with the
1736 <clix:ref>REQUEST</clix:ref> object
1737 <clix:arg>request</clix:arg>.
1741 <clix:function name='remote-addr*'>
1746 <clix:returns>address
1749 Returns the address the current request originated from.
1753 <clix:function name='remote-port*'>
1761 Returns the port the current request originated from.
1765 <clix:function name='script-name*'>
1770 <clix:returns>script-name
1773 Returns the file name of the <clix:ref>REQUEST</clix:ref>
1774 object <clix:arg>request</clix:arg>. That's the
1775 requested URI without the query string (i.e the GET
1780 <clix:accessor name='aux-request-value'>
1781 <clix:lambda-list>symbol
1785 <clix:returns>value, present-p
1788 This accessor can be used to associate arbitrary
1789 data with the the symbol <clix:arg>symbol</clix:arg> in the <clix:ref>REQUEST</clix:ref> object
1790 <clix:arg>request</clix:arg>. <clix:arg>present-p</clix:arg> is true if such data was found, otherwise <code>NIL</code>.
1794 <clix:function name='delete-aux-request-value'>
1795 <clix:lambda-list>symbol
1802 Removes the value associated with <clix:arg>symbol</clix:arg> from the <clix:ref>REQUEST</clix:ref> object
1803 <clix:arg>request</clix:arg>.
1807 <clix:function name='authorization'>
1812 <clix:returns>result
1815 Returns as two values the user and password (if any) as
1816 encoded in the 'AUTHORIZATION' header. Returns
1817 <code>NIL</code> if there is no such header.
1821 <clix:special-variable name='*hunchentoot-default-external-format*'>
1823 The external format used to compute the <clix:ref>REQUEST</clix:ref> object.
1825 </clix:special-variable>
1827 <clix:special-variable name='*file-upload-hook*'>
1829 If this is not <code>NIL</code>, it should be a unary
1830 function which will be called with a pathname for each file
1831 which is <a href="#upload">uploaded</a> to Hunchentoot. The
1832 pathname denotes the temporary file to which the uploaded
1833 file is written. The hook is called directly before the
1834 file is created. At this point,
1835 <clix:ref>*REQUEST*</clix:ref> is already bound to the
1836 current <clix:ref>REQUEST</clix:ref> object, but obviously
1837 you can't access the post parameters yet.
1839 </clix:special-variable>
1841 <clix:function name="raw-post-data">
1843 <clix:lkw>key</clix:lkw>
1844 request external-format force-text force-binary want-stream
1846 <clix:returns>raw-body-or-stream</clix:returns>
1848 Returns the content sent by the client in the request body if
1849 there was any (unless the content type
1850 was <code>multipart/form-data</code> in which
1851 case <code>NIL</code> is returned). By default, the result is
1852 a string if the type of the <code>Content-Type</code>
1853 <a href="http://www.faqs.org/rfcs/rfc1590.html">media type</a>
1854 is <code>"text"</code>, and a vector of octets otherwise. In
1855 the case of a string, the external format to be used to decode
1856 the content will be determined from the <code>charset</code>
1857 parameter sent by the client (or
1858 otherwise <clix:ref>*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT*</clix:ref>
1861 You can also provide an external format explicitly (through
1862 <clix:arg>external-format</clix:arg>) in which case the result
1863 will unconditionally be a string. Likewise, you can provide
1864 a true value for <clix:arg>force-text</clix:arg> which will
1865 force Hunchentoot to act as if the type of the media type
1866 had been <code>"text"</code>
1867 (with <clix:arg>external-format</clix:arg> taking precedence
1868 if provided). Or you can provide a true value
1869 for <clix:arg>force-binary</clix:arg> which means that you
1870 want a vector of octets at any rate. (If both
1871 <clix:arg>force-text</clix:arg>
1872 and <clix:arg>force-binary</clix:arg> are true, an error will
1876 If, however, you provide a true value
1877 for <clix:arg>want-stream</clix:arg>, the other parameters are
1878 ignored and you'll get the content (flexi) stream to read
1879 from it yourself. It is then your responsibility to read
1880 the correct amount of data, because otherwise you won't be
1881 able to return a response to the client. The stream will
1883 its <a href="http://weitz.de/flexi-streams/#flexi-streams">octet
1884 position</a> set to <code>0</code>. If the client provided
1885 a <code>Content-Length</code> header, the stream will also
1887 corresponding <a href="http://weitz.de/flexi-streams/#flexi-streams">bound</a>,
1888 so no matter whether the client used chunked encoding or
1889 not, you can always read until EOF.
1892 If the content type of the request
1893 was <code>multipart/form-data</code>
1894 or <code>application/x-www-form-urlencoded</code>, the
1895 content has been read by Hunchentoot already and you can't
1896 read from the stream anymore.
1899 You can call <clix:ref>RAW-POST-DATA</clix:ref> more than once
1900 per request, but you can't mix calls which have different
1901 values for <clix:arg>want-stream</clix:arg>.
1904 Note that this function is slightly misnamed because a
1905 client can send content even if the request method is not
1912 <clix:function name='recompute-request-parameters'>
1915 </clix:lkw> request external-format
1920 Recomputes the GET and POST parameters for the <clix:ref>REQUEST</clix:ref> object
1921 <clix:arg>request</clix:arg>. This only makes sense if you're switching external formats
1926 <clix:function generic='true' name='process-request'>
1927 <clix:lambda-list>request
1932 This function is called by <clix:ref>PROCESS-CONNECTION</clix:ref>
1933 after the incoming headers have been read. It
1934 calls <clix:ref>HANDLE-REQUEST</clix:ref> (and is more or less just a
1935 thin wrapper around it) to select and call a
1936 <a href="#request-dispatch">handler</a> and send the output of this handler to
1937 the client. Note that <clix:ref>PROCESS-CONNECTION</clix:ref> is
1938 called once per connection and loops in case of a persistent
1939 connection while <clix:ref>PROCESS-REQUEST</clix:ref> is called anew
1942 The return value of this function is ignored.
1945 Like <clix:ref>PROCESS-CONNECTION</clix:ref>, this is another function
1946 the behaviour of which you should only modify if you really, really
1947 know what you're doing.
1952 <clix:function generic='true' name='handle-request'>
1953 <clix:lambda-list>acceptor request
1955 <clix:returns>content
1958 This function is called by <clix:ref>PROCESS-REQUEST</clix:ref> once
1959 the request has been read and a <clix:ref>REQUEST</clix:ref> object
1960 has been created. Its job is to actually handle the request, i.e. to
1961 return something to the client.
1963 The default method calls the
1964 acceptor's <a href="#request-dispatch">request dispatcher</a>, but you
1965 can of course implement a different behaviour. The default method
1966 also sets up <a href="#logging">standard error handling</a> for
1967 the <a href="#request-dispatch">handler</a>.
1970 Might be a good place to bind or rebind special variables which can
1971 then be accessed by your <a href="#request-dispatch">handlers</a>.
1976 <clix:function generic='true' name='acceptor-dispatch-request'>
1977 <clix:lambda-list>acceptor request
1979 <clix:returns>content
1982 This function is called to actually dispatch the request
1983 once the standard logging and error handling has been set
1984 up. <clix:ref>ACCEPTOR</clix:ref> subclasses implement
1985 methods for this function in order to perform their own
1986 request routing. If a method does not want to handle the
1987 request, it is supposed to invoke <a
1988 href="http://www.lispworks.com/documentation/HyperSpec/Body/f_call_n.htm">CALL-NEXT-METHOD</a>
1989 so that the next <clix:ref>ACCEPTOR</clix:ref> in the
1990 inheritance chain gets a chance to handle the request.
1994 <clix:readers generic='true'>
1995 <clix:listed-reader generic='true' name='cookies-in'>
1996 <clix:lambda-list>request
1998 <clix:returns>cookies
2000 </clix:listed-reader>
2002 <clix:listed-reader generic='true' name='get-parameters'>
2003 <clix:lambda-list>request
2005 <clix:returns>get-parameters
2007 </clix:listed-reader>
2009 <clix:listed-reader generic='true' name='header-in'>
2010 <clix:lambda-list>name request
2012 <clix:returns>result
2016 </clix:listed-reader>
2018 <clix:listed-reader generic='true' name='headers-in'>
2019 <clix:lambda-list>request
2021 <clix:returns>headers
2023 </clix:listed-reader>
2025 <clix:listed-reader generic='true' name='post-parameters'>
2026 <clix:lambda-list>request
2028 <clix:returns>post-parameters
2030 </clix:listed-reader>
2032 <clix:listed-reader generic='true' name='query-string'>
2033 <clix:lambda-list>request
2035 <clix:returns>query-string
2037 </clix:listed-reader>
2039 <clix:listed-reader generic='true' name='remote-addr'>
2040 <clix:lambda-list>request
2042 <clix:returns>address
2044 </clix:listed-reader>
2046 <clix:listed-reader generic='true' name='remote-port'>
2047 <clix:lambda-list>request
2051 </clix:listed-reader>
2053 <clix:listed-reader generic='true' name='request-acceptor'>
2054 <clix:lambda-list>request
2056 <clix:returns>acceptor
2058 </clix:listed-reader>
2060 <clix:listed-reader generic='true' name='request-method'>
2061 <clix:lambda-list>request
2063 <clix:returns>method
2065 </clix:listed-reader>
2067 <clix:listed-reader generic='true' name='request-uri'>
2068 <clix:lambda-list>request
2072 </clix:listed-reader>
2074 <clix:listed-reader generic='true' name='server-protocol'>
2075 <clix:lambda-list>request
2077 <clix:returns>protocol
2079 </clix:listed-reader>
2081 <clix:listed-reader generic='true' name='script-name'>
2082 <clix:lambda-list>request
2084 <clix:returns>result
2086 </clix:listed-reader>
2089 These are various generic readers which are used
2090 to read information about a <clix:ref>REQUEST</clix:ref> object. If you are writing a
2091 <a href="#request-dispatch">handler</a>, you should <em>not</em> use these readers but instead utilize the
2092 corresponding functions with an asterisk at the end of their name,
2093 also listed in this section. These generic readers are only
2094 exported for users who want to create their own subclasses of
2095 <clix:ref>REQUEST</clix:ref>.
2102 <clix:subchapter name="replies" title="Reply objects">
2104 For each incoming request, the <a href="#acceptors">acceptor</a>
2105 (in <clix:ref>PROCESS-CONNECTION</clix:ref>) creates
2106 a <clix:ref>REPLY</clix:ref> object and makes it available
2107 to <a href="#request-dispatch">handlers</a> via the special variable
2108 <clix:ref>*REPLY*</clix:ref>. This object contains all relevant
2109 information (except for the content body) about the reply that will be
2110 sent to the client and this section collects the functions which can
2111 be used to query and modify such an object. In all function
2112 where <clix:arg>reply</clix:arg> is an optional or keyword parameter,
2113 the default is <clix:ref>*REPLY*</clix:ref>.
2116 If you need more fine-grained control over the behaviour of reply
2117 objects, you can subclass <clix:ref>REPLY</clix:ref> and initialize
2118 the <a href="#acceptor-reply-class"><code>REPLY-CLASS</code></a>
2119 slot of the <clix:ref>ACCEPTOR</clix:ref> class accordingly. The
2120 acceptor will generate reply objects of the class named by this
2124 <clix:class name='reply'>
2126 Objects of this class hold all the information about an
2127 outgoing reply. They are created automatically by
2128 Hunchentoot and can be accessed and modified by the
2129 corresponding <a href="#request-dispatch">handler</a>.
2131 You should not mess with the slots of these objects directly, but you
2132 can subclass <clix:ref>REPLY</clix:ref> in order to implement your own behaviour. See the
2133 <a href="#acceptor-reply-class"><code>:reply-class</code></a> initarg
2134 of the <clix:ref>ACCEPTOR</clix:ref> class.
2139 <clix:special-variable name='*reply*'>
2141 The current <clix:ref>REPLY</clix:ref> object in the context of a request.
2143 </clix:special-variable>
2145 <clix:accessor name='header-out'>
2146 <clix:lambda-list>name
2150 <clix:returns>string
2153 <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.
2155 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>.
2156 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>.
2161 <clix:function name='headers-out*'>
2168 <clix:description>Returns an alist of the outgoing headers associated with the
2169 <clix:ref>REPLY</clix:ref> object <clix:arg>reply</clix:arg>. See also <clix:ref>HEADER-OUT</clix:ref>.
2173 <clix:accessor name='content-length*'>
2178 <clix:returns>content-length
2181 The outgoing 'Content-Length' http header of <clix:arg>reply</clix:arg>.
2185 <clix:accessor name='content-type*'>
2190 <clix:returns>content-type
2193 The outgoing 'Content-Type' http header of <clix:arg>reply</clix:arg>.
2197 <clix:function name='cookie-out'>
2198 <clix:lambda-list>name
2202 <clix:returns>result
2205 Returns the current value of the outgoing <a
2206 href="#cookies">cookie</a> named
2207 <clix:arg>name</clix:arg>. Search is case-sensitive.
2211 <clix:accessor name='cookies-out*'>
2219 Returns or sets an alist of the outgoing <a
2220 href="#cookies">cookies</a> associated with the
2221 <clix:ref>REPLY</clix:ref> object
2222 <clix:arg>reply</clix:arg>.
2226 <clix:accessor name='return-code*'>
2231 <clix:returns>return-code
2234 Gets or sets the http return code of
2235 <clix:arg>reply</clix:arg>. The return code of each
2236 <clix:ref>REPLY</clix:ref> object is initially set to
2237 <clix:ref>+HTTP-OK+</clix:ref>.
2241 <clix:function name="send-headers">
2242 <clix:returns>stream</clix:returns>
2244 Sends the initial status line and all headers as determined
2245 by the <clix:ref>REPLY</clix:ref>
2246 object <clix:ref>*REPLY*</clix:ref>. Returns
2247 a <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_b.htm#binary">binary</a>
2248 stream to which the body of the reply can be written. Once
2249 this function has been called, further changes
2250 to <clix:ref>*REPLY*</clix:ref> don't have any effect.
2251 Also, automatic handling of errors (i.e. sending the
2252 corresponding status code to the browser, etc.) is turned
2253 off for this request and functions
2254 like <clix:ref>REDIRECT</clix:ref> or
2255 to <clix:ref>ABORT-REQUEST-HANDLER</clix:ref> won't have the
2256 desired effect once the headers are sent.
2258 If your handlers return the full body as a string or as an
2259 array of octets, you should <em>not</em> call this function.
2260 If a handler calls <clix:ref>SEND-HEADERS</clix:ref> , its
2261 return value is ignored.
2266 <clix:accessor name='reply-external-format*'>
2271 <clix:returns>external-format
2274 Gets or sets the external format of <clix:arg>reply</clix:arg> which is used for character output.
2278 <clix:special-variable name='*default-content-type*'>
2280 The default content-type header which is returned to the client.
2282 </clix:special-variable>
2285 <clix:listed-constant name="+http-continue+"/>
2286 <clix:listed-constant name="+http-switching-protocols+"/>
2287 <clix:listed-constant name="+http-ok+"/>
2288 <clix:listed-constant name="+http-created+"/>
2289 <clix:listed-constant name="+http-accepted+"/>
2290 <clix:listed-constant name="+http-non-authoritative-information+"/>
2291 <clix:listed-constant name="+http-no-content+"/>
2292 <clix:listed-constant name="+http-reset-content+"/>
2293 <clix:listed-constant name="+http-partial-content+"/>
2294 <clix:listed-constant name="+http-multi-status+"/>
2295 <clix:listed-constant name="+http-multiple-choices+"/>
2296 <clix:listed-constant name="+http-moved-permanently+"/>
2297 <clix:listed-constant name="+http-moved-temporarily+"/>
2298 <clix:listed-constant name="+http-see-other+"/>
2299 <clix:listed-constant name="+http-not-modified+"/>
2300 <clix:listed-constant name="+http-use-proxy+"/>
2301 <clix:listed-constant name="+http-temporary-redirect+"/>
2302 <clix:listed-constant name="+http-bad-request+"/>
2303 <clix:listed-constant name="+http-authorization-required+"/>
2304 <clix:listed-constant name="+http-payment-required+"/>
2305 <clix:listed-constant name="+http-forbidden+"/>
2306 <clix:listed-constant name="+http-not-found+"/>
2307 <clix:listed-constant name="+http-method-not-allowed+"/>
2308 <clix:listed-constant name="+http-not-acceptable+"/>
2309 <clix:listed-constant name="+http-proxy-authentication-required+"/>
2310 <clix:listed-constant name="+http-request-time-out+"/>
2311 <clix:listed-constant name="+http-conflict+"/>
2312 <clix:listed-constant name="+http-gone+"/>
2313 <clix:listed-constant name="+http-length-required+"/>
2314 <clix:listed-constant name="+http-precondition-failed+"/>
2315 <clix:listed-constant name="+http-request-entity-too-large+"/>
2316 <clix:listed-constant name="+http-request-uri-too-large+"/>
2317 <clix:listed-constant name="+http-unsupported-media-type+"/>
2318 <clix:listed-constant name="+http-requested-range-not-satisfiable+"/>
2319 <clix:listed-constant name="+http-expectation-failed+"/>
2320 <clix:listed-constant name="+http-failed-dependency+"/>
2321 <clix:listed-constant name="+http-internal-server-error+"/>
2322 <clix:listed-constant name="+http-not-implemented+"/>
2323 <clix:listed-constant name="+http-bad-gateway+"/>
2324 <clix:listed-constant name="+http-service-unavailable+"/>
2325 <clix:listed-constant name="+http-gateway-time-out+"/>
2326 <clix:listed-constant name="+http-version-not-supported+"/>
2328 The values of these constants are 100, 101, 200, 201, 202,
2329 203, 204, 205, 206, 207, 300, 301, 302, 303, 304, 305, 307,
2330 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411,
2331 412, 413, 414, 415, 416, 417, 424, 500, 501, 502, 503, 504,
2332 and 505. See <clix:ref>RETURN-CODE</clix:ref>.
2336 <clix:readers generic='true'>
2337 <clix:listed-reader generic='true' name='content-length'>
2338 <clix:lambda-list>reply
2340 <clix:returns>content-length
2342 </clix:listed-reader>
2344 <clix:listed-reader generic='true' name='content-type'>
2345 <clix:lambda-list>reply
2347 <clix:returns>content-type
2349 </clix:listed-reader>
2351 <clix:listed-reader generic='true' name='headers-out'>
2352 <clix:lambda-list>reply
2354 <clix:returns>headers-out
2356 </clix:listed-reader>
2359 These are various generic readers which are used
2360 to read information about a <clix:ref>REPLY</clix:ref> object. If you are writing a
2361 <a href="#request-dispatch">handler</a>, you should <em>not</em> use these readers but instead utilize the
2362 corresponding functions with an asterisk at the end of their name,
2363 also listed in this section. These generic readers are only
2364 exported for users who want to create their own subclasses of
2365 <clix:ref>REPLY</clix:ref>.
2369 <clix:accessors generic='true'>
2370 <clix:listed-accessor generic='true' name='cookies-out'>
2371 <clix:lambda-list>reply
2373 <clix:returns>result
2375 </clix:listed-accessor>
2377 <clix:listed-accessor generic='true' name='return-code'>
2378 <clix:lambda-list>reply
2380 <clix:returns>result
2382 </clix:listed-accessor>
2384 <clix:listed-accessor generic='true' name='reply-external-format'>
2385 <clix:lambda-list>reply
2387 <clix:returns>result
2389 </clix:listed-accessor>
2392 These are various generic accessors which are
2393 used to query and modify a <clix:ref>REPLY</clix:ref> objects. If
2395 <a href="#request-dispatch">handler</a>, you should <em>not</em> use these
2396 accessors but instead utilize the corresponding functions with an
2397 asterisk at the end of their name, also listed in this section.
2398 These generic accessors are only exported for users who want to
2399 create their own subclasses of
2400 <clix:ref>REPLY</clix:ref>.
2407 <clix:subchapter name="sessions" title="Sessions">
2408 Hunchentoot supports <em>sessions</em>: Once a <a href="#request-dispatch">request
2409 handler</a> has called <clix:ref>START-SESSION</clix:ref>, Hunchentoot
2410 uses either cookies or (if the client doesn't send the cookies
2411 back) <a href="#*rewrite-for-session-urls*">rewrites URLs</a> to keep
2412 track of this client, i.e. to provide a kind of 'state' for the
2413 stateless http protocol. The session associated with the client is a
2414 <a href="#session">CLOS object</a> which can be used
2415 to <a href="#session-value">store arbitrary data</a> between requests.
2417 Hunchentoot makes some reasonable effort to prevent eavesdroppers from
2418 hijacking sessions (see below), but this should not be considered
2419 really secure. Don't store sensitive data in sessions and rely solely
2420 on the session mechanism as a safeguard against malicious users who
2421 want to get at this data!
2424 For each request there's one <clix:ref>SESSION</clix:ref> object which is accessible to the
2425 <a href="#handler">handler</a> via the special
2426 variable <clix:ref>*SESSION*</clix:ref>. This object holds all the
2427 information available about the session and can be accessed with the
2428 functions described in this chapter. Note that the internal structure
2429 of <clix:ref>SESSION</clix:ref> objects should be considered opaque
2430 and may change in future releases of Hunchentoot.
2433 Sessions are automatically <a href="#session-verify">verified</a> for
2434 validity and age when the <clix:ref>REQUEST</clix:ref> object is
2435 instantiated, i.e. if <clix:ref>*SESSION*</clix:ref> is not NIL then
2436 this session is valid (as far as Hunchentoot is concerned) and
2437 not <a href="#session-too-old-p">too old</a>. Old sessions
2438 are <a href="#session-gc">automatically removed</a>.
2441 <clix:class name='session'>
2443 <clix:ref>SESSION</clix:ref> objects are
2444 automatically maintained by Hunchentoot. They should not be created
2445 explicitly with <code>MAKE-INSTANCE</code> but implicitly
2446 with <clix:ref>START-SESSION</clix:ref> and they should be treated as
2449 You can ignore Hunchentoot's <clix:ref>SESSION</clix:ref> objects and
2450 <a href="#session-behaviour">implement your own sessions</a> if you provide corresponding methods for
2451 <clix:ref>SESSION-COOKIE-VALUE</clix:ref>
2452 and <clix:ref>SESSION-VERIFY</clix:ref>.
2457 <clix:function name='start-session'>
2460 <clix:returns>session
2463 Returns the current <clix:ref>SESSION</clix:ref>
2464 object. If there is no current session, creates one and updates the
2465 corresponding data structures. In this case the function will also
2466 send a session cookie to the browser.
2470 <clix:accessor name='session-value'>
2471 <clix:lambda-list>symbol
2475 <clix:returns>value, present-p
2478 This accessor can be used to associate arbitrary data with the the
2479 symbol <clix:arg>symbol</clix:arg> in the <clix:ref>SESSION</clix:ref>
2480 object <clix:arg>session</clix:arg>. <clix:arg>present-p</clix:arg> is
2481 true if such data was found, otherwise <code>NIL</code>. The default
2482 value for <clix:arg>session</clix:arg> is
2483 <clix:ref>*SESSION*</clix:ref>.
2485 If <code>SETF</code> of <clix:ref>SESSION-VALUE</clix:ref> is called
2486 with <clix:arg>session</clix:arg> being <code>NIL</code> then a
2487 session is automatically instantiated
2488 with <clix:ref>START-SESSION</clix:ref>.
2493 <clix:function name='delete-session-value'>
2494 <clix:lambda-list>symbol
2501 Removes the value associated with
2502 <clix:arg>symbol</clix:arg> from
2503 <clix:arg>session</clix:arg> if there is one.
2507 <clix:special-variable name='*session*'>
2509 The current session while in the context of a request, or
2512 </clix:special-variable>
2514 <clix:function name='remove-session'>
2515 <clix:lambda-list>session
2520 Completely removes the <clix:ref>SESSION</clix:ref> object
2521 <clix:arg>session</clix:arg> from Hunchentoot's
2522 internal <a href="#session-db">session database</a>.
2526 <clix:function name='reset-sessions'>
2529 </clix:lkw> acceptor
2534 Removes <em>all</em> stored sessions of
2535 <clix:arg>acceptor</clix:arg>. The default for
2536 <clix:arg>acceptor</clix:arg> is
2537 <clix:ref>*ACCEPTOR*</clix:ref>.
2541 <clix:special-variable name='*rewrite-for-session-urls*'>
2543 Whether HTML pages should possibly be rewritten for cookie-less
2546 </clix:special-variable>
2548 <clix:special-variable name='*content-types-for-url-rewrite*'>
2550 The content types for which url-rewriting is OK. See
2551 <clix:ref>*REWRITE-FOR-SESSION-URLS*</clix:ref>.
2553 </clix:special-variable>
2555 <clix:special-variable name='*use-remote-addr-for-sessions*'>
2557 Whether the client's remote IP (as returned by <clix:ref>REAL-REMOTE-ADDR</clix:ref>)
2558 should be encoded into the session string. If this value is true, a
2559 session will cease to be accessible if the client's remote IP changes.
2561 This might for example be an issue if the client uses a proxy server
2562 which doesn't send correct 'X-Forwarded-For' headers.
2565 </clix:special-variable>
2567 <clix:function generic='true' name='session-remote-addr'>
2568 <clix:lambda-list>session
2570 <clix:returns>remote-addr
2573 The remote IP address of the client when this session was started (as
2574 returned by <clix:ref>REAL-REMOTE-ADDR</clix:ref>).
2578 <clix:special-variable name='*use-user-agent-for-sessions*'>
2579 <clix:description>Whether the 'User-Agent' header should
2580 be encoded into the session string. If this value is true, a session
2581 will cease to be accessible if the client sends a different
2582 'User-Agent' header.
2584 </clix:special-variable>
2586 <clix:function generic='true' name='session-user-agent'>
2587 <clix:lambda-list>session
2589 <clix:returns>user-agent
2592 The incoming 'User-Agent' header that
2593 was sent when this session was created.
2597 <clix:accessor generic='true' name='session-max-time'>
2598 <clix:lambda-list>session
2600 <clix:returns>max-time
2603 Gets or sets the time (in seconds) after
2604 which <clix:arg>session</clix:arg> expires if it's not used.
2609 <clix:special-variable name='*session-max-time*'>
2611 The default time (in seconds) after which a session times out.
2613 </clix:special-variable>
2615 <clix:special-variable name='*session-gc-frequency*'>
2617 A session GC (see function <clix:ref>SESSION-GC</clix:ref>) will happen every
2618 <clix:ref>*SESSION-GC-FREQUENCY*</clix:ref> requests (counting only
2619 requests which create a new session) if this variable is
2620 not <code>NIL</code>. See <clix:ref>SESSION-CREATED</clix:ref>.
2622 </clix:special-variable>
2624 <clix:function name='session-gc'>
2630 Removes sessions from the current session database which are
2631 too old - see <clix:ref>SESSION-TOO-OLD-P</clix:ref>.
2635 <clix:function name='session-too-old-p'>
2636 <clix:lambda-list>session
2638 <clix:returns>generalized-boolean
2641 Returns true if the <clix:ref>SESSION</clix:ref> object <clix:arg>session</clix:arg> has not been active in
2642 the last <code>(session-max-time session)</code> seconds.
2646 <clix:function generic='true' name='session-id'>
2647 <clix:lambda-list>session
2649 <clix:returns>session-id
2652 The unique ID (an INTEGER) of the session.
2656 <clix:function generic='true' name='session-start'>
2657 <clix:lambda-list>session
2659 <clix:returns>universal-time
2662 The time this session was started.
2669 <clix:subchapter name="session-behaviour" title="Customizing session behaviour">
2671 For everyday session usage, you will probably just
2672 use <clix:ref>START-SESSION</clix:ref>,
2673 <clix:ref>SESSION-VALUE</clix:ref>,
2674 and maybe <clix:ref>DELETE-SESSION-VALUE</clix:ref>
2675 and <clix:ref>*SESSION*</clix:ref>. However, there are two ways to
2676 customize the way Hunchentoot maintains sessions.
2678 One way is to mostly leave the session mechanism intact but to tweak
2681 <li>The publicly visible part of a session is encoded using a
2682 <a href="#*session-secret*">secret</a> which you can set yourself.</li>
2683 <li>And it is stored using a cookie (or GET
2684 parameter) <a href="#session-cookie-name">name</a> that you can
2686 <li>Each session receives a <a href="#next-session-id">new ID</a> when
2687 it is created and you can implement a more robust way to do that.</li>
2688 <li>You can arrange to be called whenever a session
2689 is <a href="#session-created">created</a> to trigger some action. You
2690 might also do this to invent your own
2691 session <a href="#session-gc">garbage collection</a>.</li>
2692 <li>By default, all sessions are stored in a global alist in memory.
2693 You can't change the alist part, but you can distribute your sessions
2694 over different <a href="#session-db">"databases"</a>.</li>
2695 <li>By default, every operation which modifies sessions or one of the
2696 session databases is guarded by a global lock, but you can arrange to
2697 <a href="#session-db-lock">provide</a> different locks for this.</li>
2701 The other way to customize Hunchentoot's sessions is to completely
2702 replace them. This is actually pretty easy: Create your own class to
2703 store state (which doesn't have to and probably shouldn't inherit
2704 from <clix:ref>SESSION</clix:ref>) and implement methods for
2705 <clix:ref>SESSION-VERIFY</clix:ref>
2706 and <clix:ref>SESSION-COOKIE-VALUE</clix:ref> - that's it.
2707 Hunchentoot will continue to use cookies and/or to rewrite URLs to
2708 keep track of session state and it will store "the current session"
2709 (whatever that is in your implementation)
2710 in <clix:ref>*SESSION*</clix:ref>. Everything else (like persisting
2711 sessions, GC, getting and setting values) you'll have to take care of
2712 yourself and the other session functions
2713 (like <clix:ref>START-SESSION</clix:ref> or
2714 <clix:ref>SESSION-VALUE</clix:ref>) won't work anymore. (Almost)
2715 total freedom, but a lot of responsibility as well... :)
2718 <clix:special-variable name='*session-secret*'>
2720 A random ASCII string that's used to encode the public
2721 session data. This variable is initially unbound and will
2722 be set (using <clix:ref>RESET-SESSION-SECRET</clix:ref>) the
2723 first time a session is created, if necessary. You can
2724 prevent this from happening if you set the value yourself
2725 before starting <a href="#acceptors">acceptors</a>.
2727 </clix:special-variable>
2729 <clix:function name='reset-session-secret'>
2732 <clix:returns>secret
2735 Sets <clix:ref>*SESSION-SECRET*</clix:ref> to a
2736 new random value. All old sessions will cease to be valid.
2740 <clix:function generic='true' name='session-cookie-name'>
2741 <clix:lambda-list>acceptor
2746 Returns the name (a string) of the cookie (or
2747 the GET parameter) which is used to store a session on the client
2748 side. The default is to use the
2749 string <code>"hunchentoot-session"</code>, but you can
2750 specialize this function if you want another name.
2754 <clix:function generic='true' name='session-created'>
2755 <clix:lambda-list>acceptor new-session
2757 <clix:returns>result
2760 This function is called whenever a new session
2761 has been created. There's a default method which might trigger
2762 a <a href="#session-gc">session GC</a> based on the value of
2763 <clix:ref>*SESSION-GC-FREQUENCY*</clix:ref>.
2765 The return value is ignored.
2770 <clix:function generic='true' name='next-session-id'>
2771 <clix:lambda-list>acceptor
2776 Returns the next sequential session ID, an
2777 integer, which should be unique per session. The default method uses
2778 a simple global counter and isn't guarded by a lock. For a
2779 high-performance production environment you might consider using a
2780 more robust implementation.
2784 <clix:accessor generic='true' name='session-db'>
2785 <clix:lambda-list>acceptor
2787 <clix:returns>database
2790 Returns the current session database which is an
2791 alist where each car is a session's ID and the cdr is the
2792 corresponding <clix:ref>SESSION</clix:ref> object itself. The default
2793 is to use a global list for all acceptors.
2797 <clix:function generic='true' name='session-db-lock'>
2798 <clix:lambda-list>acceptor
2800 </clix:lkw> whole-db-p
2805 A function which returns a lock that will be
2806 used to prevent concurrent access to sessions. The first argument
2807 will be the <a href="#acceptors">acceptor</a> that handles the
2808 current <a href="#requests">request</a>, the second argument is true
2809 if the whole (current) session database is modified. If it
2810 is <code>NIL</code>, only one existing session in the database is
2813 This function can return <code>NIL</code> which means that sessions or
2814 session databases will be modified without a lock held (for example
2815 for single-threaded environments). The default is to always return a
2816 global lock (ignoring the <clix:arg>acceptor</clix:arg> argument) for
2817 Lisps that support threads and <code>NIL</code> otherwise.
2822 <clix:function generic='true' name='session-verify'>
2823 <clix:lambda-list>request
2825 <clix:returns>session-or-nil
2828 Tries to get a session identifier from the cookies
2829 (or alternatively from the GET parameters) sent by the client (see
2830 <clix:ref>SESSION-COOKIE-NAME</clix:ref>
2831 and <clix:ref>SESSION-COOKIE-VALUE</clix:ref>). This identifier is
2832 then checked for validity against the <clix:ref>REQUEST</clix:ref>
2834 <clix:arg>request</clix:arg>. On success the corresponding session object (if not too
2835 old) is returned (and updated). Otherwise <code>NIL</code> is returned.
2837 A default method is provided and you only need to write your own one
2838 if you want to maintain your own sessions.
2843 <clix:function generic='true' name='session-cookie-value'>
2844 <clix:lambda-list>session
2846 <clix:returns>string
2849 Returns a string which can be used to safely
2850 restore the session <clix:arg>session</clix:arg> if as session has
2851 already been established. This is used as the value stored in the
2852 session cookie or in the corresponding GET parameter and verified
2853 by <clix:ref>SESSION-VERIFY</clix:ref>.
2856 method is provided and there's no reason to change it unless you
2857 want to use your own session objects.
2864 <clix:subchapter name="cookies" title="Cookies">
2866 Outgoing cookies are stored in the request's <clix:ref>REPLY</clix:ref>
2867 object (see <clix:ref>COOKIE-OUT</clix:ref>
2868 and <clix:ref>COOKIES-OUT*</clix:ref>). They are CLOS objects
2871 <pre>(defclass cookie ()
2872 ((name :initarg :name
2873 :reader <a class="noborder" name="cookie-name">cookie-name</a>
2875 :documentation "The name of the cookie - a string.")
2876 (value :initarg :value
2877 :accessor <a class="noborder" name="cookie-value">cookie-value</a>
2879 :documentation "The value of the cookie. Will be URL-encoded when sent to the browser.")
2880 (expires :initarg :expires
2882 :accessor <a class="noborder" name="cookie-expires">cookie-expires</a>
2883 :documentation "The time (a universal time) when the cookie expires (or NIL).")
2884 (path :initarg :path
2886 :accessor <a class="noborder" name="cookie-path">cookie-path</a>
2887 :documentation "The path this cookie is valid for (or NIL).")
2888 (domain :initarg :domain
2890 :accessor <a class="noborder" name="cookie-domain">cookie-domain</a>
2891 :documentation "The domain this cookie is valid for (or NIL).")
2892 (secure :initarg :secure
2894 :accessor <a class="noborder" name="cookie-secure">cookie-secure</a>
2895 :documentation "A generalized boolean denoting whether this is a secure cookie.")
2896 (http-only :initarg :http-only
2898 :accessor <a class="noborder" name="cookie-http-only">cookie-http-only</a>
2899 :documentation "A generalized boolean denoting whether this is a <a href="http://msdn2.microsoft.com/en-us/library/ms533046.aspx">HttpOnly</a> cookie.")))
2902 The <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_r.htm#reader">reader</a>
2903 <clix:ref>COOKIE-NAME</clix:ref> and
2904 the <a href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_a.htm#accessor">accessors</a>
2905 <clix:ref>COOKIE-VALUE</clix:ref>, <clix:ref>COOKIE-EXPIRES</clix:ref>,
2906 <clix:ref>COOKIE-PATH</clix:ref>, <clix:ref>COOKIE-DOMAIN</clix:ref>, <clix:ref>COOKIE-SECURE</clix:ref>,
2907 and <clix:ref>COOKIE-HTTP-ONLY</clix:ref> are all exported from
2908 the <code>HUNCHENTOOT</code> package. For now, the class name itself is <em>not</em> exported.
2910 <clix:function name="set-cookie">
2912 name <clix:lkw>key</clix:lkw> value expires path
2913 domain secure http-only reply
2915 <clix:returns>cookie</clix:returns>
2917 Creates a <code>COOKIE</code> object from the parameters
2918 provided to this function and adds it to the outgoing cookies
2919 of the <a href="#replies"><code>REPLY</code> object</a>
2920 <clix:arg>reply</clix:arg>. If a cookie with the same name
2921 (case-sensitive) already exists, it is replaced. The default
2922 for <clix:arg>reply</clix:arg>
2923 is <clix:ref>*REPLY*</clix:ref>. The default
2924 for <clix:arg>value</clix:arg> is the empty string.
2928 <clix:function name="set-cookie*">
2929 <clix:lambda-list>cookie <clix:lkw>optional</clix:lkw> reply</clix:lambda-list>
2930 <clix:returns>cookie</clix:returns>
2932 Adds the <code>COOKIE</code> object <clix:arg>cookie</clix:arg>
2933 to the outgoing cookies of
2934 the <a href="#replies"><code>REPLY</code> object</a>
2935 <clix:arg>reply</clix:arg>. If a cookie with the same name
2936 (case-sensitive) already exists, it is replaced. The default
2937 for <clix:arg>reply</clix:arg> is <clix:ref>*REPLY*</clix:ref>.
2942 <clix:subchapter name="logging" title="Logging">
2943 Hunchentoot can log accesses and diagnostic messages to two
2944 separate destinations, which can be either files in the file
2945 system or streams. Logging can also be disabled by setting the
2946 <clix:code>ACCESS-LOG-DESTINATION</clix:code> and
2947 <clix:code>MESSAGE-LOG-DESTINATION</clix:code> slots in the
2948 <clix:ref>ACCEPTOR</clix:ref> to <code>NIL</code>. The two
2949 slots can be initialized by providing the
2950 :ACCESS-LOG-DESTINATION and :MESSAGE-LOG-DESTINATION
2951 initialization arguments when creating the acceptor or set by
2952 setting the slots through its
2953 <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref> and
2954 <clix:ref>ACCEPTOR-ACCESS-LOG-DESTINATION</clix:ref> accessors.
2956 When the path for the message or accept log is set to a
2957 variable holding an output stream, hunchentoots writes
2958 corresponding log entries to that stream. By default,
2959 Hunchentoot logs to *STANDARD-ERROR*.
2962 Access logging is done in a format similar to what
2963 the Apache web server can write so that logfile analysis using
2964 standard tools is possible. Errors during request processing are
2965 logged to a separate file.
2968 The standard logging mechanism is deliberately simple and slow. The
2969 log files are opened for each log entry and closed again after
2970 writing, and access to them is protected by a global lock. Derived
2971 acceptor classes can implement methods for the
2972 <clix:ref>ACCEPTOR-LOG-MESSAGE</clix:ref> and
2973 <clix:ref>ACCEPTOR-LOG-ACCESS</clix:ref> generic functions in order to
2974 log differently (e.g. to a central logging server or in a different
2978 Errors happening within a <a href="#request-dispatch">handler</a>
2979 which are not caught by the handler itself are handled by
2980 Hunchentoot by logging them to the established
2981 <clix:ref>ACCEPTOR-MESSAGE-LOG-DESTINATION</clix:ref>.
2984 <clix:function name='log-message*'>
2985 <clix:lambda-list>log-level format-string
2987 </clix:lkw> format-arguments
2989 <clix:returns>result
2992 Convenience function which calls the message
2993 logger of the current acceptor (if there is one) with the same
2994 arguments it accepts. Returns <code>NIL</code> if there is no message
2995 logger or whatever the message logger returns.
2997 This is the function which Hunchentoot itself uses to log errors it
2998 catches during request processing.
3003 <clix:special-variable name='*log-lisp-errors-p*'>
3005 Whether Lisp errors in request handlers should be logged.
3007 </clix:special-variable>
3009 <clix:special-variable name='*log-lisp-backtraces-p*'>
3011 Whether Lisp backtraces should be logged. Only
3012 has an effect if <clix:ref>*LOG-LISP-ERRORS-P*</clix:ref> is true
3015 </clix:special-variable>
3017 <clix:special-variable name='*log-lisp-warnings-p*'>
3019 Whether Lisp warnings in request handlers should be logged.
3021 </clix:special-variable>
3023 <clix:special-variable name='*lisp-errors-log-level*'>
3025 Log level for Lisp errors. Should be one
3026 of <code>:ERROR</code> (the default), <code>:WARNING</code>,
3027 or <code>:INFO</code>.
3029 </clix:special-variable>
3031 <clix:special-variable name='*lisp-warnings-log-level*'>
3033 Log level for Lisp warnings.
3034 Should be one of <code>:ERROR</code>, <code>:WARNING</code>
3035 (the default), or <code>:INFO</code>.
3037 </clix:special-variable>
3040 <clix:subchapter name="conditions" title="Conditions and error handling">
3042 This section describes how Hunchentoot deals with exceptional
3043 situations. See also the secion about <a href="#logging">logging</a>.
3046 When an error occurs while processing a request, Hunchentoot's
3047 default behavior is to catch catch the error, log it and
3048 optionally display it to the client in the HTML response.
3049 This behavior can be customized through the values of a number
3050 of special variables, which are documented below.
3053 <clix:special-variable name='*catch-errors-p*'>
3055 If the value of this variable is <code>NIL</code>
3056 (the default is <code>T</code>), then errors which happen while a
3057 request is handled aren't <a href="#logging">caught as usual</a>, but
3060 href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_d.htm#debugger">debugger</a>
3062 href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invoke.htm">invoked</a>.
3063 This variable should obviously always be set to a <em>true</em> value
3064 in a production environment.
3065 See <clix:ref>MAYBE-INVOKE-DEBUGGER</clix:ref>
3066 if you want to fine-tune this behaviour.
3068 </clix:special-variable>
3070 <clix:special-variable name='*show-lisp-errors-p*'>
3072 Whether Lisp errors should be shown in HTML output. Note
3073 that this only affects canned responses generated by Lisp.
3074 If an error template is present for the "internal server
3075 error" status code, this special variable is not used (see
3076 <clix:ref>acceptor-status-message</clix:ref>).
3078 </clix:special-variable>
3080 <clix:special-variable name='*show-lisp-backtraces-p*'>
3082 Whether Lisp backtraces should be shown in HTML output if
3083 <clix:ref>*SHOW-LISP-ERRORS-P*</clix:ref> is true and an error occurs.
3085 </clix:special-variable>
3087 <clix:function generic='true' name='maybe-invoke-debugger'>
3088 <clix:lambda-list>condition
3093 This generic function is called whenever a
3095 href="http://www.lispworks.com/documentation/HyperSpec/Body/09_.htm">condition</a> <code><i>condition</i></code>
3096 is signaled in Hunchentoot. You might want to specialize it on
3097 specific condition classes for debugging purposes. The default
3099 href="http://www.lispworks.com/documentation/HyperSpec/Body/f_invoke.htm">invokes
3100 the debugger</a> with <clix:arg>condition</clix:arg> if
3101 <clix:ref>*CATCH-ERRORS-P*</clix:ref> is <code>NIL</code>.
3105 <clix:condition name='hunchentoot-condition'>
3107 Superclass for all conditions related to Hunchentoot.
3111 <clix:condition name='hunchentoot-error'>
3113 Superclass for all errors related to Hunchentoot and a subclass of <clix:ref>HUNCHENTOOT-CONDITION</clix:ref>.
3117 <clix:condition name='parameter-error'>
3119 Signalled if a function was called with incosistent or illegal parameters. A subclass of <clix:ref>HUNCHENTOOT-ERROR</clix:ref>.
3123 <clix:condition name='hunchentoot-warning'>
3125 Superclass for all warnings related to Hunchentoot and a subclass of <clix:ref>HUNCHENTOOT-CONDITION</clix:ref>.
3131 <clix:subchapter name="misc" title="Miscellaneous">
3133 Various functions and variables which didn't fit into one of the
3136 <clix:function name='abort-request-handler'>
3141 <clix:returns>result
3144 This function can be called by a request handler
3145 at any time to immediately abort handling the request. This works as
3146 if the handler had returned <clix:arg>result</clix:arg>. See the
3147 source code of <clix:ref>REDIRECT</clix:ref> for an example.
3151 <clix:function name="handle-if-modified-since">
3152 <clix:lambda-list>time <clix:lkw>optional</clix:lkw> request</clix:lambda-list>
3153 <clix:returns>|</clix:returns>
3155 This function is designed to be used inside
3156 a <a href="#request-dispatch">handler</a>. If the client has sent an
3157 'If-Modified-Since' header
3158 (see <a href="http://www.faqs.org/rfcs/rfc2616.html">RFC 2616</a>,
3159 section 14.25) and the time specified matches the universal
3161 <clix:arg>time</clix:arg> then the
3162 header <clix:ref>+HTTP-NOT-MODIFIED+</clix:ref> with no content
3163 is immediately returned to the client.
3165 Note that for this function to be useful you should usually
3166 send 'Last-Modified' headers back to the client. See the
3168 of <clix:ref>CREATE-STATIC-FILE-DISPATCHER-AND-HANDLER</clix:ref>
3174 <clix:function name="handle-static-file">
3175 <clix:lambda-list>path <clix:lkw>optional</clix:lkw> content-type</clix:lambda-list>
3176 <clix:returns>nil</clix:returns>
3178 Sends the file denoted by the pathname designator
3179 <clix:arg>path</clix:arg> with content type
3180 <clix:arg>content-type</clix:arg> to the client. Sets the
3181 necessary handlers. In particular the function employs
3182 <clix:ref>HANDLE-IF-MODIFIED-SINCE</clix:ref>.
3184 If <clix:arg>content-type</clix:arg> is <code>NIL</code> the
3185 function tries to determine the correct content type from
3186 the file's suffix or falls back
3187 to <code>"application/octet-stream"</code> as a last resort.
3190 Note that this function
3191 calls <clix:ref>SEND-HEADERS</clix:ref> internally, so after
3192 you've called it, the headers are sent and the return value
3193 of your handler is ignored.
3198 <clix:function name="redirect">
3199 <clix:lambda-list>target <clix:lkw>key</clix:lkw> host port protocol add-session-id code</clix:lambda-list>
3200 <clix:returns>|</clix:returns>
3202 Sends back appropriate headers to redirect the client
3203 to <clix:arg>target</clix:arg> (a string).
3205 If <clix:arg>target</clix:arg> is a full URL starting with a
3206 scheme, <clix:arg>host</clix:arg>, <clix:arg>port</clix:arg>,
3207 and <clix:arg>protocol</clix:arg> are ignored.
3208 Otherwise, <clix:arg>target</clix:arg> should denote the path
3209 part of a URL, <clix:arg>protocol</clix:arg> must be one of
3210 the keywords <code>:HTTP</code> or <code>:HTTPS</code>, and
3211 the URL to redirect to will be constructed
3212 from <clix:arg>host</clix:arg>, <clix:arg>port</clix:arg>, <clix:arg>protocol</clix:arg>,
3213 and <clix:arg>target</clix:arg>.
3216 <clix:arg>code</clix:arg> must be a 3xx HTTP redirection
3217 status code to send to the client. It defaults to 302
3218 ("Found"). If <clix:arg>host</clix:arg> is not provided,
3219 the current host (see <clix:ref>HOST</clix:ref>) will be
3220 used. If <clix:arg>protocol</clix:arg> is the keyword
3221 <code>:HTTPS</code>, the client will be redirected to a
3222 https URL, if it's <code>:HTTP</code> it'll be sent to a
3223 http URL. If both <clix:arg>host</clix:arg> and
3224 <clix:arg>protocol</clix:arg> aren't provided, then the
3225 value of <clix:arg>protocol</clix:arg> will match the
3231 <clix:function name="require-authorization">
3232 <clix:lambda-list><clix:lkw>optional</clix:lkw> realm</clix:lambda-list>
3233 <clix:returns>|</clix:returns>
3235 Sends back appropriate headers to require basic HTTP
3237 (see <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617</a>)
3238 for the realm <clix:arg>realm</clix:arg>. The default value
3239 for <clix:arg>realm</clix:arg> is <code>"Hunchentoot"</code>.
3243 <clix:function name='no-cache'>
3249 Adds appropriate headers to completely prevent caching on most browsers.
3253 <clix:function name='ssl-p'>
3256 </clix:lkw> acceptor
3258 <clix:returns>generalized-boolean
3261 Whether the current connection to the client is secure. See <clix:ref>ACCEPTOR-SSL-P</clix:ref>.
3265 <clix:function name='reason-phrase'>
3266 <clix:lambda-list>return-code
3268 <clix:returns>string
3271 Returns a reason phrase for the HTTP return code <clix:arg>return-code</clix:arg>
3272 (which should be an integer) or <code>NIL</code> for return codes Hunchentoot
3277 <clix:function name='rfc-1123-date'>
3282 <clix:returns>string
3285 Generates a time string according to <a href="http://www.faqs.org/rfcs/rfc1123.html">RFC 1123</a>. Default is current time.
3286 This can be used to send a 'Last-Modified' header - see <clix:ref>HANDLE-IF-MODIFIED-SINCE</clix:ref>.
3290 <clix:function name='url-encode'>
3291 <clix:lambda-list>string
3293 </clix:lkw> external-format
3295 <clix:returns>string
3298 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>.
3302 <clix:function name='url-decode'>
3303 <clix:lambda-list>string
3305 </clix:lkw> external-format
3307 <clix:returns>string
3310 Decodes a URL-encoded string which is assumed to
3311 be encoded using the external
3312 format <clix:arg>external-format</clix:arg>, i.e. this is the inverse
3313 of <clix:ref>URL-ENCODE</clix:ref>. It is assumed that you'll rarely
3314 need this function, if ever. But just in case - here it is. The
3315 default for <clix:arg>external-format</clix:arg> is the value
3316 of <clix:ref>*HUNCHENTOOT-DEFAULT-EXTERNAL-FORMAT*</clix:ref>.
3320 <clix:function name='escape-for-html'>
3321 <clix:lambda-list>string
3323 <clix:returns>result
3326 Escapes the characters #\<, #\>, #\', #\", and #\& for HTML output.
3330 <clix:function name="http-token-p">
3331 <clix:lambda-list>object</clix:lambda-list>
3332 <clix:returns>generalized-boolean</clix:returns>
3334 This function tests whether <clix:arg>object</clix:arg> is a
3335 non-empty string which is a <em>token</em> according
3336 to <a href="http://www.faqs.org/rfcs/rfc2068.html">RFC
3337 2068</a> (i.e. whether it may be used for, say, cookie names).
3341 <clix:function name='mime-type'>
3342 <clix:lambda-list>pathspec
3344 <clix:returns>result
3347 Given a pathname designator <clix:arg>pathspec</clix:arg> returns the <a href="http://en.wikipedia.org/wiki/Internet_media_type">MIME type</a>
3348 (as a string) corresponding to the suffix of the file denoted by
3349 <clix:arg>pathspec</clix:arg> (or <code>NIL</code>).
3353 <clix:function name='within-request-p'>
3356 <clix:returns>generalized-boolean
3359 Returns true if in the context of a request. Otherwise, <code>NIL</code>.
3363 <clix:special-variable name="*tmp-directory*">
3365 This should be a pathname denoting a directory where temporary
3366 files can be stored. It is used for <a href="#upload">file
3369 </clix:special-variable>
3371 <clix:special-variable name='*header-stream*'>
3373 If this variable is not <code>NIL</code>, it should be bound to a stream to
3374 which incoming and outgoing headers will be written for debugging
3377 </clix:special-variable>
3380 <clix:special-variable name='*cleanup-function*'>
3382 A designator for a function without arguments which is called on a
3383 regular basis if <clix:ref>*CLEANUP-INTERVAL*</clix:ref> is not <code>NIL</code>. The initial value is
3384 the name of a function which invokes a garbage collection on 32-bit
3385 versions of LispWorks.
3387 This variable is only available on LispWorks.
3390 </clix:special-variable>
3392 <clix:special-variable name='*cleanup-interval*'>
3394 Should be <code>NIL</code> or a positive integer. The system calls
3395 <clix:ref>*CLEANUP-FUNCTION*</clix:ref>
3396 whenever <clix:ref>*CLEANUP-INTERVAL*</clix:ref> new worker threads
3397 (counted globally across all acceptors) have been created unless the
3398 value is <code>NIL</code>. The initial value is 100.
3400 This variable is only available on LispWorks.
3403 </clix:special-variable>
3407 <clix:chapter name="testing" title="Testing">
3408 Hunchentoot comes with a test script which verifies that the
3409 example web server responds as expected. This test script uses the
3410 <a href="http://weitz.de/drakma/">Drakma</a> HTTP client library
3411 and thus shares a significant amount of its base code with
3412 Hunchentoot itself. Still, running the test script is a useful
3413 confidence test, and it is also possible to run the script across
3414 machines in order to verify a new Hunchentoot (or, for that matter
3417 To run the confidence test, <a href="#start">start
3418 the example web server</a>. Then, in your Lisp
3420 <pre>(<a class="noborder" href="hunchentoot-test:test-hunchentoot">hunchentoot-test:test-hunchentoot</a> "http://localhost:4242")</pre>
3421 You will see some diagnostic output and a summary line that
3422 reports whether any tests have failed. (You can also use the
3423 example certificate and key files in the test directory and
3424 start and test an https server instead.)
3427 <clix:function name="hunchentoot-test:test-hunchentoot">
3428 <clix:lambda-list>base-url <clix:lkw>key</clix:lkw></clix:lambda-list>
3429 <clix:returns>|</clix:returns>
3431 Runs the built-in confidence
3432 test. <clix:arg>base-url</clix:arg> is the base URL to use
3433 for testing, it should not have a trailing slash. The keyword
3434 arguments accepted are for future extension and should not
3437 The script expects the Hunchentoot example test server to be
3438 running at the given <clix:arg>base-url</clix:arg> and
3439 retrieves various pages from that server, expecting certain
3446 <clix:chapter name="debugging" title="Debugging">
3447 By default, Hunchentoot intercepts all errors that occur while
3448 executing request handlers, logs them to the log file and displays
3449 a static error page to the user. While developing applications,
3450 you may want to change that behavior so that the debugger is
3451 invoked when an error occurs. You can set
3452 the <clix:ref>*CATCH-ERRORS-P*</clix:ref> to <code>NIL</code> to
3453 make that happen. Alternatively, you may want to have Hunchentoot
3454 display detailed error information in the error response page.
3455 You can set the <clix:ref>*SHOW-LISP-ERRORS-P*</clix:ref> to a
3456 true value to make that happen. If you don't want to see Lisp
3457 backtraces in these error pages, you can
3458 set <clix:ref>*SHOW-LISP-BACKTRACES-P*</clix:ref>
3459 to <code>NIL</code>.
3462 <clix:chapter name="history" title="History">
3464 Hunchentoot's predecessor <a href="http://weitz.de/tbnl/">TBNL</a>
3465 (which is short for "To Be Named Later") grew over the years as a
3466 toolkit that I used for various commercial and private
3467 projects. In August 2003, Daniel Barlow started
3468 a <a href="http://article.gmane.org/gmane.lisp.web/148">review of
3470 the <a href="http://www.red-bean.com/lispweb/">lispweb</a> mailing
3472 I <a href="http://article.gmane.org/gmane.lisp.web/153">described</a>
3473 the API of my hitherto-unreleased bunch of code (and christened it
3477 <a href="http://www.jeffcaldwell.com/">Jeff Caldwell</a> had
3478 worked on something similar so he emailed me and proposed to
3479 join our efforts. As I had no immediate plans to release my code
3480 (which was poorly organized, undocumented, and mostly
3481 CMUCL-specific), I gave it to Jeff and he worked towards a
3482 release. He added docstrings, refactored, added some stuff, and
3483 based it on KMRCL to make it portable across several Lisp
3487 Unfortunately, Jeff is at least as busy as I am so he didn't
3488 find the time to finish a full release. But in spring 2004 I
3489 needed a documented version of the code for a client of mine who
3490 thought it would be good if the toolkit were publicly available
3491 under an open source license. So I took Jeff's code, refactored
3492 again (to sync with the changes I had done in the meantime), and
3493 added documentation. This resulted in TBNL 0.1.0 (which
3494 initially required mod_lisp as its front-end).
3497 In March 2005, Bob Hutchinson sent patches which enabled TBNL to
3498 use other front-ends than mod_lisp. This made me aware that
3499 TBNL was already <em>almost</em> a full web server, so
3500 eventually I wrote Hunchentoot which <em>was</em> a full web
3501 server, implemented as a wrapper around TBNL. Hunchentoot 0.1.0
3502 was released at the end of 2005 and was originally
3506 Hunchentoot 0.4.0, released in October 2006, was the first
3507 release which also worked with other Common Lisp
3508 implementations. It is a major rewrite and also incorporates
3509 most of TBNL and replaces it completely.
3512 Hunchentoot 1.0.0, released in February 2009, is again a major
3513 rewrite and should be considered work in progress. It moved to
3515 the <a href="http://common-lisp.net/project/usocket/">usocket</a>
3516 and <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux
3517 Threads</a> libraries for non-LispWorks Lisps, thereby removing most of
3518 the platform dependent code. Threading behaviour was made
3519 controllable through the introduction of
3520 taskmasters. <a href="http://www.cliki.net/mod_lisp">mod_lisp</a>
3521 support and several other things were removed in this release to
3522 simplify the code base (and partly due to the lack of interest).
3523 Several architectural changes (lots of them not
3524 backwards-compatible) were made to ease customization of
3525 Hunchentoot's behaviour. A significant part of the 1.0.0
3527 by <a href="http://netzhansa.blogspot.com/">Hans Hübner</a>.
3531 <clix:chapter name="index" title="Symbol index">
3533 Here are all exported symbols of the <code>HUNCHENTOOT</code>
3534 package in alphabetical order linked to their corresponding
3535 documentation entries:
3541 <clix:chapter name="ack" title="Acknowledgements">
3543 Thanks to Jeff Caldwell - TBNL would not have been released
3544 without his efforts. Thanks
3545 to <a href="http://www.cliki.net/Stefan%20Scholl">Stefan
3546 Scholl</a> and Travis Cross for various additions and fixes to
3547 TBNL, to <a href="http://www.foldr.org/~michaelw/">Michael
3548 Weber</a> for initial file upload code, and
3549 to <a href="http://www.ltn.lv/~jonis/">Janis Dzerins</a> for
3550 his <a href="http://common-lisp.net/project/rfc2388/">RFC 2388
3551 code</a>. Thanks to Bob Hutchison for his code for multiple
3552 front-ends (which made me realize that TBNL was already pretty
3553 close to a "real" web server) and the initial UTF-8 example.
3554 Thanks to <a href="http://netzhansa.blogspot.com/">Hans Hübner</a>
3555 for a lot of architectural and implementation enhancements for the
3556 1.0.0 release and also for transferring the documentation to sane
3557 XHTML. Thanks to John
3558 Foderaro's <a href="http://opensource.franz.com/aserve/index.html">AllegroServe</a>
3559 for inspiration. Thanks to <a href="http://www.htg1.de/">Uwe von
3561 the <a href="http://www.htg1.de/hunchentoot/hunchentoot.html">Hunchentoot
3565 Hunchentoot originally used code
3566 from <a href="http://www.cliki.net/ACL-COMPAT">ACL-COMPAT</a>,
3567 specifically the chunking code from Jochen Schmidt. (This has been
3568 replaced by <a href="http://weitz.de/chunga/">Chunga</a>.) When I ported
3569 Hunchentoot to other Lisps than LispWorks, I stole code from
3570 ACL-COMPAT, <a href="http://www.cliki.net/kmrcl">KMRCL</a>,
3571 and <a href="http://www.cliki.net/trivial-sockets">trivial-sockets</a> for
3572 implementation-dependent stuff like sockets and MP. (This has been replaced by
3573 <a href="http://common-lisp.net/project/bordeaux-threads/">Bordeaux
3575 and <a href="http://common-lisp.net/project/usocket/">usocket</a>.)
3578 Parts of this documentation were prepared
3579 with <a href="http://weitz.de/documentation-template/">DOCUMENTATION-TEMPLATE</a>,
3580 no animals were harmed.
3584 <a href='http://weitz.de/index.html'>BACK TO MY HOMEPAGE
3587 </clix:documentation>