5.1 General
"dispatchers/dispatch.ss" provides a few functions for dispatchers in general.
Equivalent to (-> connection? request? void).
any : any/c |
Returns #t if any is 'v1. Returns #f otherwise.
|
An exception thrown to indicate that a dispatcher does not apply to a particular request.
(next-dispatcher) → void |
Raises a exn:dispatcher
As the dispatcher? contract suggests, a dispatcher is a function that takes a connection and request object and does something to them. Mostly likely it will generate some response and output it on the connection, but it may do something different. For example, it may apply some test to the request object, perhaps checking for a valid source IP address, and error if the test is not passed, and call next-dispatcher otherwise.
Consider the following example dispatcher, that captures the essence of URL rewriting:
; (url? -> url?) dispatcher? -> dispatcher? |
(lambda (rule inner) |
(lambda (conn req) |
; Call the inner dispatcher... |
(inner conn |
; with a new request object... |
(copy-struct request req |
; with a new URL! |
[request-uri (rule (request-uri req))])))) |