3 Launching Servers
This module provides functions for launching dispatching servers.
If connection-close? is #t, then every connection is
closed after one request. Otherwise, the client decides based on what
HTTP version it uses.
The
tcp@ argument supports replacing TCP connections with
other kinds of connections (and was formerly recommended for SSL
support). Beware that the server expects the
tcp-accept
operation from
tcp@ to be effectively atomic; new connections
are not accepted while
tcp-accept is in progress.
The
max-waiting and
request-read-timeout arguments
are supported for backwards compatability.
If a
safety-limits argument is given, the
max-waiting and
request-read-timeout arguments are ignored;
otherwise, they are passed to
make-safety-limits to construct
the
safety limits value.
If neither
max-waiting,
request-read-timeout,
nor
safety-limits are given, the default
safety limits value
is equivalent to
(make-safety-limits).
Here’s an example of a simple web server that serves files
from a given path:
Calls
serve multiple times, once for each
port, and returns
a function that shuts down all of the server instances.
Changed in version 1.6 of package web-server-lib: Added the safety-limits argument as with serve:
see compatability note.
(serve/ips+ports | | | | #:dispatch dispatch | | | [ | #:confirmation-channel confirmation-channel | | | | #:connection-close? connection-close? | | | | #:dispatch-server-connect@ dispatch-server-connect@ | | | | #:tcp@ tcp@ | | | | #:ips+ports ips+ports | | | | #:max-waiting max-waiting | | | | #:initial-connection-timeout request-read-timeout | | | | #:safety-limits safety-limits]) | |
|
→ (-> any) |
dispatch : dispatcher/c |
| confirmation-channel | | : | | | | | | = | | #f |
|
connection-close? : boolean? = #f |
|
tcp@ : (unit/c (import) (export tcp^)) = raw:tcp@ |
|
max-waiting : exact-nonnegative-integer? = 511 |
request-read-timeout : timeout/c = 60 |
|
Calls
serve/ports multiple times, once for each
ip, and returns
a function that shuts down all of the server instances.
Changed in version 1.1 of package web-server-lib: Added the #:dispatch-server-connect@ argument.
Changed in version 1.6: Added the safety-limits argument as with serve:
see compatability note.
Starts the Web Server with the settings defined by the given
web-config*^ unit.
A default implementation of the dispatch server’s connection-conversion abstraction that performs no conversion.
Added in version 1.1 of package web-server-lib.
Constructs an implementation of the dispatch server’s connection-conversion abstraction for OpenSSL.
Added in version 1.1 of package web-server-lib.
This function does not return. If you are writing a script to load the Web Server
you may want to call this functions at the end of your script.
3.1 Simple Single Servlet Servers
These functions optimize the construction of dispatchers and launching of servers for single servlets and interactive development.
serve/servlet starts a server and uses a particular dispatching sequence. For some applications, this
nails down too much, but users are conflicted, because the interface is so convenient. For those users,
dispatch/servlet
does the hardest part of
serve/servlet and constructs a dispatcher just for the
start servlet.
The dispatcher responds to requests that match regexp. The current directory
of servlet execution is servlet-current-directory.
If stateless? is true, then the servlet is run as a stateless
module and
stuffer is used
as the
stuffer.
The servlet is loaded with
manager as its continuation manager. (The default manager limits the amount of memory to 64 MB and
deals with memory pressure as discussed in the
make-threshold-LRU-manager documentation.)
If a servlet fails to load, responders-servlet-loading is used. If a servlet errors during its operation, responders-servlet is used.
The other interesting part of
serve/servlet is its ability to start up a server and immediately
launch a browser at it. This is provided by
serve/launch/wait.
It starts a server using the result of make-dispatcher as the dispatcher.
The make-dispatcher argument is called with
a semaphore that, if posted, will cause the server to quit.
If launch-path is not false, then a browser is launched with that path appended to the URL to the server itself.
If banner? is true, then a banner is printed informing the user of the server’s URL.
The server listens on listen-ip and port port. If listen-ip is #f, then the server accepts
connections to all of the listening machine’s addresses. Otherwise, the server accepts connections only at the interface(s) associated with the given string.
For example, providing "127.0.0.1" (the default) as listen-ip creates a server that accepts only connections to "127.0.0.1" (the loopback interface) from the local machine.
If ssl-key and ssl-cert are not false, then the server runs in HTTPS mode with ssl-cert
and ssl-key as paths to the certificate and private key.
If connection-close? is #t, then every connection is closed after one
request. Otherwise, the client decides based on what HTTP version it uses.
The
safety-limits argument supplies a
safety limits
value specifying the policies to be used while reading and handling requests.
The
max-waiting argument is supported for backwards compatability.
If a
safety-limits argument is given, the
max-waiting
argument is ignored; otherwise, it is passed to
make-safety-limits
to construct the
safety limits value.
If neither
max-waiting nor
safety-limits are given,
the default
safety limits value is equivalent to
(make-safety-limits).
Changed in version 1.6 of package web-server-lib: Added the safety-limits argument:
see compatability note.