On this page:
dispatcher?
dispatcher-interface-version?
exn: dispatcher
next-dispatcher
Version: 4.1

5.1 General

 (require web-server/dispatchers/dispatch)

"dispatchers/dispatch.ss" provides a few functions for dispatchers in general.

dispatcher? : contract?

Equivalent to (-> connection? request? void).

(dispatcher-interface-version? any)  boolean?

  any : any/c

Returns #t if any is 'v1. Returns #f otherwise.

(struct

 

exn:dispatcher

 

())

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))]))))