2.1 General

► |  | Web Server: HTTP Server

1 | Dispatching Server
2 | Dispatchers
3 | Launching Servers
4 | Web Servers
5 | Internal APIs
6 | Troubleshooting and Tips
| Index

▼ | 2 | Dispatchers

2.1 | General
2.2 | Mapping URLs to Paths
2.3 | Sequencing
2.4 | Timeouts
2.5 | Lifting Procedures
2.6 | Filtering Requests by URL
2.7 | Filtering Requests by Method
2.8 | Procedure Invocation upon Request
2.9 | Logging
2.10 | Basic Logging
2.11 | Password Protection
2.12 | Virtual Hosts
2.13 | Serving Files
2.14 | Serving Servlets
2.15 | Statistics
2.16 | Limiting Requests
2.17 | Wrapping Requests & Responses

On this page:

dispatcher/ c
dispatcher-interface-version/ c
exn: dispatcher
next-dispatcher

Racket
top contents ← prev up next →

### 2.1 General🔗ℹ

(require web-server/dispatchers/dispatch)
| package: web-server-lib

This module provides a few functions for dispatchers in general.

> value dispatcher/c : contract?

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

Changed in version 1.3 of package web-server-lib: Weakened the range contract to allow any

> procedure (dispatcher-interface-version/c any) → boolean?
> any : any/c

Equivalent to (symbols 'v1)

> > struct
> > (struct |  | exn:dispatcher ()
> #:extra-constructor-name make-exn:dispatcher)

An exception thrown to indicate that a dispatcher does not apply to a particular request.

> procedure (next-dispatcher) → any

Raises a exn:dispatcher
As the dispatcher/c 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/c -> dispatcher/c
> (lambda (rule inner)
> (lambda (conn req)
> ; Call the inner dispatcher...
> (inner conn
> ; with a new request object...
> (struct-copy request req
> ; with a new URL!
> [request-uri (rule (request-uri req))]))))

top contents ← prev up next →