Expand description
Built-in middleware. Each piece is an async function with the
signature async fn(Request, Next) -> Result<Response>. Drop any of
them into Router::middleware(...) in whatever order you want.
Structs§
- Correlation
Id - Wrapper carried in the request context so handlers can pull it
out via
req.ctx().get::<CorrelationId>(). The inner string is the UUID rendered in hyphenated lowercase form. - Csrf
Guard - A value a handler can pull out of the request context to embed in a rendered form. Lightweight; just wraps a string.
- Locale
- Wrapper carried in the request context so handlers can pull
the negotiated locale out via
req.ctx().get::<Locale>(). The inner string is the tag as it appeared inAccept-Language(e.g."en","en-US","ar-EG"), already validated. - Rate
Limiter
Constants§
- CORRELATION_
ID_ HEADER - Response + request header name. Lower-case to keep parity with the HTTP/2 wire format and to match what other observability tooling (OpenTelemetry, Cloudflare, etc.) writes.
- CSRF_
HEADER - DEFAULT_
LOCALE - Fallback locale when no header is sent, the header parses to
nothing valid, or the project app didn’t mount the middleware.
"en"matches the framework’s existing default strings (every label and button is currently English).
Functions§
- correlation_
id - Middleware: attach a UUID v7 to every request, surface it in the response, and stash it in the request context for the audit pipeline to pick up.
- csrf_
protect - gzip
- locale
- Middleware: parse the inbound
Accept-Languageheader and stash the negotiated locale in the request context. Falls back toDEFAULT_LOCALEwhen the header is absent or contains no valid tag. Never fails — locale negotiation is best-effort by design, and a missing or malformed header collapses to the default rather than rejecting the request. - logger
- parse_
accept_ language - Parse an
Accept-Languageheader value, returning the first language tag that passes the validator. Pulled out as a free function so the negotiation policy is unit-testable without aRequest. - rate_
limit - The middleware function. Wrap a limiter into a closure and hand
it to
Router::middleware(...). - security_
headers