4 Web Servers
A Web server is a unit with the web-server^ signature. The most common way to construct one is to provide a web-config^ unit to the
web-server@ unit. The most common way to construct a web-config^ unit is to use configuration-table->web-config@ to produce
one from a configuration table file, such as the one that is shipped with Racket in default-configuration-table-path.
4.1 Server Units
Runs the server and returns a procedure that shuts down the server.
Serves a single connection represented by the ports ip and
op.
Uses the
web-config^ to construct a
dispatcher/c
function that sets up one virtual host dispatcher, for each virtual
host in the
web-config^, that sequences the following
operations:
Logs the incoming request with the given format to the given file
Performs HTTP Basic Authentication with the given password file
Allows the "/conf/refresh-passwords" URL to refresh the password file.
Allows the "/conf/collect-garbage" URL to call the garbage collector.
Allows the "/conf/refresh-servlets" URL to refresh the servlets cache.
Executes servlets mapping URLs to the given servlet root directory under htdocs.
Serves files under the "/" URL in the given htdocs directory.
Using this
dispatcher/c, it loads a dispatching server that provides
serve
and
serve-ports functions that operate as expected.
4.2 Configuration Units
Provides contains the following identifiers.
Contains the configuration of individual virtual hosts.
Specifies the initial timeout given to a connection.
Specifies the port to serve HTTP on.
Parses
sexpr as a configuration-table and constructs a
web-config^ unit.
4.3 Configuration Table
This module provides functions for
reading, writing, parsing, and printing
configuration-table
structures.
The default configuration table S-expression file.
`((port ,integer?) |
(max-waiting ,exact-integer?) |
(initial-connection-timeout ,integer?) |
(default-host-table |
,host-table-sexpr?) |
(virtual-host-table |
(list ,symbol? ,host-table-sexpr?) |
...)) |
where a host-table-sexpr is:
`(host-table |
(default-indices ,string? ...) |
(log-format ,symbol?) |
(messages |
(servlet-message ,path-string?) |
(authentication-message ,path-string?) |
(servlets-refreshed ,path-string?) |
(passwords-refreshed ,path-string?) |
(file-not-found-message ,path-string?) |
(protocol-message ,path-string?) |
(collect-garbage ,path-string?)) |
(timeouts |
(default-servlet-timeout ,integer?) |
(password-connection-timeout ,integer?) |
(servlet-connection-timeout ,integer?) |
(file-per-byte-connection-timeout ,integer?) |
(file-base-connection-timeout ,integer)) |
(paths |
(configuration-root ,path-string?) |
(host-root ,path-string?) |
(log-file-path ,path-string?) |
(file-root ,path-string?) |
(servlet-root ,path-string?) |
(mime-types ,path-string?) |
(password-authentication ,path-string?))) |
In this syntax, the 'messages paths are relative to the
'configuration-root directory. All the paths in
'paths except for 'servlet-root are relative to
'host-root (other than 'host-root obviously.)
The 'servlet-root path is relative to 'file-root.
Note: You almost always want to leave everything in the 'paths section the default except the 'host-root.
4.4 Configuration Table Structure
This module provides the following structures that
represent a standard configuration (see
Server Units) of the Web Server .
The contracts on this structure influence the valid types of values in
the configuration table S-expression file format described in
Configuration Table.
4.5 Standard Responders
This module provides some functions that help constructing HTTP
responders. These functions are used by the default dispatcher
constructor (see
Server Units) to turn the paths given in
the
configuration-table into responders for the associated
circumstance.
Generates a
response? with the given
http-code and
short-version as the corresponding fields; with the content of
the
text-file as the body; and, with the
headers as,
you guessed it, headers.
This does not cause redirects to a well-known URL, such as
"conf/not-found.html", but rather use the contents of
"not-found.html" (for example) as its contents. Therefore, any
relative URLs in
text-file are relative to whatever URL
file-response is used to respond
to. Thus, you should
probably use absolute URLs in these files.
Gives exn to the current-error-handler and response
with a stack trace and a "Servlet didn’t load" message.
Returns a function that generates a standard "Servlet not found." error
with content from file.
Gives exn to the current-error-handler and response
with a stack trace and a "Servlet error" message.
Prints the
exn to standard output and responds with a "Servlet
error." message with content from
file.
Returns a function that generates a standard "Servlet cache refreshed."
message with content from file.
Returns a function that generates a standard "Passwords refreshed."
message with content from file.
Returns a function that generates an authentication failure error with
content from
file and
header as the HTTP header.
Returns a function that generates a "Malformed request" error with
content from file.
Returns a function that generates a standard "File not found" error
with content from file.
Returns a function that generates a standard "Garbage collection run"
message with content from file.