2.17 Wrapping Requests & Responses

► |  | 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:

make

top contents ← prev up next →

#### 2.17`` Wrapping Requests & Responses🔗ℹ

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

The web-server/dispatchers/dispatch-wrap module provides a general-purpose wrapping dispatcher that allows one to intercept an incoming request as well as the response returned by other servlets

> procedure (make servlet req-trans res-trans) → dispatcher/c
> servlet : (-> request? response?)
> req-trans : (-> request? request?)
> res-trans : (-> response? response?)

Returns a dispatcher that wraps res-trans around servlet, which itself receives requests transformed by req-trans. Put differently, the servlet underlying the dispatcher returned by make is equivalent to (λ (r) (res-trans (servlet (req-trans r)))).

If you’re not interested in transforming requests, pass in identity (the identity function) for req-trans. Similarly, using identity for res-trans will cause responses to pass through unchanged. (Using identity for both req-trans and res-trans is equivalent to just using servlet as-is.)

A typical use case for this dispatcher would be to inject headers into requests or responses. Similarly, functionally updating existing headers also fits into this pattern. Since the entire request – not just its headers – is available to req-trans (and similarly for the response and res-trans), arbitrary rewriting of request/response bodies is possible. Side effects in req-trans and res-trans are permitted as long as make’s contracts are adhered to.

Changed in version 1.9 of package web-server-lib: First version of this dispatcher

top contents ← prev up next →