Runs an http server listening at the given address, with the given servlet.
A servlet is a procedure which takes four arguments: a
(chibi config)
config object, an Http-Request
record,
which contains the I/O ports and parsed request and headers;
a next
procedure to call the next available servlet if any,
and a restart
procedure to restart the servlets with a new
request.
The default config parameters are:
port
: the port to listen on, default 8000doc-root
: the directory to serve files from, default the directory of the config file, or "." if no configindex-regexp
: an SRE matching index files to serve in place of a directory listing when browsing directories, default "index.html"
A simple page view counter could be run as:
(let ((count 0))
(run-http-server
8000
(lambda (cfg request next restart)
(set! count (+ 1 count))
(servlet-write request (sxml->xml `(html (body (p ,count))))))))