2.12 Serving Servlets
The first return value flushes the cache. If its optional argument is
#f (the default), all servlet caches are flushed. Otherwise,
only those servlet caches to which url->path maps the given
URLs are flushed. The second return value is a procedure that uses
url->path to resolve the URL to a path, then uses
path->servlet to resolve that path to a servlet, caching the
results in an internal table.
Changed in version 126.96.36.199 of package web-server-lib: Added optional argument to first return value.
|(make|| ||url->servlet|| |
| || [||#:responders-servlet-loading responders-servlet-loading|| |
| || ||#:responders-servlet responders-servlet])|| |
| → dispatcher/c|
| url->servlet : url->servlet/c|
This dispatcher runs racket servlets, using url->servlet to
resolve URLs to the underlying servlets. If servlets have errors
loading, then responders-servlet-loading is used. Other errors
are handled with responders-servlet. If a servlet raises calls
next-dispatcher, then the signal is propagated by this
2.12.1 Setting Up Servlets
This module is used internally to build and load servlets. It may be useful to those who are trying to extend the server.
Creates a version 1 servlet that uses directory as its current directory, a timeout manager with a timeout timeout, and start as the request handler.
Creates a version 2 servlet that uses directory as its current directory, a manager as the continuation manager, and start as the request handler.
Creates a stateless web-server
servlet that uses directory
as its current directory, stuffer
as its stuffer, and manager
as the continuation manager, and start
as the request handler.
The modules that the Web Server needs to share with all servlets.
Constructs a procedure that loads a servlet from the path in a namespace created with make-servlet-namespace,
using a timeout manager with timeouts-default-servlet as the default timeout (if no manager is given.)
2.12.2 Servlet Namespaces
This function creates a function that when called will construct a new
that has all the modules from
well as racket
, provided they are already
attached to the (current-namespace)
of the call-site.
188.8.131.52 Why this is useful
A different namespace is needed for each servlet, so that if servlet A
and servlet B both use a stateful module C, they will be isolated from
one another. We see the Web Server as an operating system for servlets,
so we inherit the isolation requirement on operating systems.
However, there are some modules which must be shared. If they were not,
then structures cannot be passed from the Web Server to the servlets,
because Racket’s structures are generative.
Since, on occasion, a user will actually wanted servlets A and B to
interact through module C. A custom make-servlet-namespace can
be created, through this procedure, that attaches module C to all
servlet namespaces. Through other means (see Dispatchers)
different sets of servlets can share different sets of modules.
2.12.3 Internal Servlet Representation
Instances of this structure hold the necessary parts of a servlet:
responsible for the servlet’s resources,
the servlet is executed within,
responsible for the servlet’s continuations,
the current directory
of the servlet,
and the handler
for all requests to the servlet.