Skip to main content

Module middleware

Module middleware 

Source
Expand description

Built-in middleware helpers for common cross-cutting concerns.

Provides pre-configured CORS and request-ID layers, plus re-exports of Axum’s middleware combinators.

Modules§

future
Future types.

Structs§

AddExtension
Middleware for adding some shareable value to request extensions.
CorsConfig
Configuration for the CORS middleware.
FromExtractor
Middleware that runs an extractor and discards the value.
FromExtractorLayer
Layer that applies FromExtractor that runs an extractor and discards the value.
FromFn
A middleware created from an async function.
FromFnLayer
A tower::Layer from an async function.
MapRequest
A middleware created from an async function that transforms a request.
MapRequestLayer
A tower::Layer from an async function that transforms a request.
MapResponse
A middleware created from an async function that transforms a response.
MapResponseLayer
A tower::Layer from an async function that transforms a response.
Next
The remainder of a middleware stack, including the handler.
ResponseAxumBody
Service generated by ResponseAxumBodyLayer.
ResponseAxumBodyFuture
Response future for ResponseAxumBody.
ResponseAxumBodyLayer
Layer that transforms the Response body to crate::body::Body.
UuidRequestId
UUID v4 request ID generator.

Statics§

X_REQUEST_ID
Header name used for request IDs.

Traits§

IntoMapRequestResult
Trait implemented by types that can be returned from map_request, map_request_with_state.

Functions§

cache_control
Returns a layer that sets the Cache-Control response header if not already present.
cors
Returns a CORS layer with permissive defaults suitable for development.
cors_with_config
Returns a CORS layer configured according to the given CorsConfig.
from_extractor
Create a middleware from an extractor.
from_extractor_with_state
Create a middleware from an extractor with the given state.
from_fn
Create a middleware from an async function.
from_fn_with_state
Create a middleware from an async function with the given state.
map_request
Create a middleware from an async function that transforms a request.
map_request_with_state
Create a middleware from an async function that transforms a request, with the given state.
map_response
Create a middleware from an async function that transforms a response.
map_response_with_state
Create a middleware from an async function that transforms a response, with the given state.
no_cache
Returns a layer that sets Cache-Control: no-cache, no-store, must-revalidate if the response does not already include a Cache-Control header.
no_store
Returns a layer that sets Cache-Control: no-store if the response does not already include a Cache-Control header.
request_id
Returns a tuple of layers that set and propagate an x-request-id header.
timeout
Returns a layer that fails requests which are not completed within the given duration.