/web/app/middleware
Production HTTP middlewares: CSRF, CORS, session, rate limiting, security headers, auth, tracing, and scripts injection.
Constants#
*scripts-accumulator*#
constant · AnyDynamic accumulator collecting ES module script specifiers during SSR or Stage rendering.
(Array)*scripts-seen*#
constant · AnyDynamic deduplication set tracking script specifiers already emitted for the current response.
nonedefault-scripts-insertion-marker#
constant · AnyDefault HTML placeholder comment replaced with injected ES module `<script type="module">` tags.
"<!--scripts-middleware-slot-->"Functions & symbols#
allow-methods-middleware#
Rejects methods outside allowlist with 405 and Allow header.
| Parameter | Type | Optional | Description |
|---|---|---|---|
allowed-methods | Any | required | — |
next-handler | Any | required | — |
Anybasic-auth-middleware#
Enforces HTTP Basic authentication using `verify-fn` (supports curried `(basic-auth-middleware verify-fn)` and direct forms).
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anybearer-auth-middleware#
Authenticates API requests via `Authorization: Bearer <token>`. Supports both `(bearer-auth-middleware verify-fn next-handler)` and curried `((bearer-auth-middleware verify-fn) next-handler)` forms.
| Parameter | Type | Optional | Description |
|---|---|---|---|
verify-fn | Any | required | — |
next-handler | Any | required | — |
Anybody-size-limit-middleware#
Limits request payload size and returns 413 when known size exceeds max-bytes.
| Parameter | Type | Optional | Description |
|---|---|---|---|
max-bytes | Any | required | — |
next-handler | Any | required | — |
Anycors-middleware#
Middleware applying CORS headers and handling preflight `OPTIONS` requests according to `options`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anycsrf-middleware#
Middleware validating synchronizer/double-submit CSRF tokens on state-changing HTTP requests.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anycurrent-form-of#
Extracts the validated form struct stored on `req:attrs:_form` by `validate-form-middleware`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
Anyetag-middleware#
Middleware that generates Weak ETags (W/"<16-hex-hash>") using a-hash (15+ GB/s) for GET/HEAD 200 OK responses. Returns 304 Not Modified with zero body payload when the client If-None-Match header matches.
| Parameter | Type | Optional | Description |
|---|---|---|---|
inner-handler | Any | required | — |
Anyhreflang-alternates#
Renders `#html` `<link rel="alternate" hreflang="..." href="...">` elements from `{:base-url :path :alternates :x-default}`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
spec | Any | required | — |
Anyi18n-middleware#
Web middleware negotiating locale and binding `*locale*` / `*bundle*`. Supports `(i18n-middleware next-handler)`, `(i18n-middleware options)` (curried), and `(i18n-middleware options next-handler)`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anyinject-scripts-into-html#
Injects script imports at the configured marker or before </body>.
| Parameter | Type | Optional | Description |
|---|---|---|---|
html | Any | required | — |
scripts | Any | required | — |
insertion-marker | Any | required | — |
Anymethod-override-middleware#
Middleware that rewrites `POST` requests to `PUT`, `PATCH`, or `DELETE` via `X-HTTP-Method-Override` header or `_method` form field.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anymount-localized-routes#
Mounts a list of localized route prefixes into `/web/app` `:scope` blocks matching `router.tan`'s contract. Usage: `(mount-localized-routes prefixes routes)` or `(mount-localized-routes prefixes middlewares routes)`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
prefixes | Any | required | — |
rest | Any | optional | — |
Anynegotiate-locale#
Negotiates the active BCP 47 locale tag for `req`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
rest | Any | optional | — |
Anynegotiate-locale-info#
Negotiates the active locale and returns `{:locale tag :source :path | :resolver | :cookie | :accept-language | :default}`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
req | Any | required | — |
rest | Any | optional | — |
Anyparse-accept-language#
Parses an RFC 4647 `Accept-Language` header into quality-sorted `{:tag :language :region :q}` entries.
| Parameter | Type | Optional | Description |
|---|---|---|---|
header-str | Any | required | — |
Anyrate-limit-middleware#
Bounded in-memory fixed-window rate limiter middleware. Supports `(rate-limit-middleware options next-handler)`, `(rate-limit-middleware next-handler)`, and curried `((rate-limit-middleware options) next-handler)`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anyrequest-id-middleware#
Ensures request-id is available in attrs and returned in response headers.
| Parameter | Type | Optional | Description |
|---|---|---|---|
next-handler | Any | required | — |
Anyscripts-middleware#
Middleware that accumulates `(use-script ...)` module specifiers and injects them into HTML or Stage slot responses.
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anysecurity-headers-middleware#
Middleware injecting defensive HTTP security headers (CSP, X-Frame-Options, Referrer-Policy, X-Content-Type-Options).
| Parameter | Type | Optional | Description |
|---|---|---|---|
args | Any | optional | — |
Anysession-middleware#
Session middleware factory. Creates middleware that manages sessions via cookies. Parameters: store - Session store instance (from construct-session-store) options - Configuration map: :cookie-name - Cookie name (default: "SESSION-ID") :max-age - Session lifetime in seconds (default: 3600) :secure - Set Secure flag on cookie (default: false) :same-site - SameSite policy: "Strict", "Lax", or "None" (default: "Lax") :path - Cookie path (default: "/") :domain - Cookie domain (default: not set)
| Parameter | Type | Optional | Description |
|---|---|---|---|
store | Any | required | — |
options | Any | required | — |
Anystatic-files-middleware#
Middleware serving static files from `./public` before falling back to `next-handler`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
next-handler | Any | required | — |
Anytraceparent-middleware#
Middleware propagating W3C `traceparent` / `x-trace-id` distributed tracing context headers.
| Parameter | Type | Optional | Description |
|---|---|---|---|
next-handler | Any | required | — |
Anytracing-middleware#
Middleware logging request method, URI, response status, and elapsed duration.
| Parameter | Type | Optional | Description |
|---|---|---|---|
next-handler | Any | required | — |
Anyuse-script#
Registers an ES module script specifier to be imported on the current page or Stage slot payload.
| Parameter | Type | Optional | Description |
|---|---|---|---|
script | Any | required | — |
Anyvalidate-form-middleware#
Route middleware that parses and validates `req` into `struct-type`, short-circuiting with 422 on `ValidationErrors` and storing the valid struct at `req:attrs:_form`.
| Parameter | Type | Optional | Description |
|---|---|---|---|
struct-type | Any | required | — |
rest | Any | optional | — |
Any