Skip to main content

Module middleware

Module middleware 

Source
Expand description

Tower middleware helpers.

Re-exports§

pub use crate::context::ClientKind;
pub use crate::context::IdentityExtractor;
pub use crate::context::RequestContext;
pub use crate::context::RequestIdentity;
pub use crate::context::api_key_identity;
pub use crate::context::client_ip_identity;
pub use crate::context::context_identity;
pub use crate::context::trusted_proxy_client_ip_identity;

Structs§

ApiDefaults
High-level configurable API defaults built from explicit Axum/Tower primitives.
BodyLimitLayer
Tower layer that rejects requests with a declared oversized body.
BodyLimitService
Service produced by BodyLimitLayer.
CatchPanicLayer
Tower layer that catches panics from the inner service.
CatchPanicService
Service produced by CatchPanicLayer.
InMemoryRateLimitStore
In-memory rate-limit store intended for local development and single-process apps.
MetricsLayer
Tower layer that invokes HttpMetricsHook for request lifecycle metrics.
MetricsService
Service produced by MetricsLayer.
PrometheusMetrics
In-memory Prometheus-format HTTP metrics collector.
RateLimitConfig
Typed config for production-shaped rate limiting.
RateLimitDecision
Decision returned by a rate-limit store.
RateLimitError
Error returned by rate-limit stores.
RateLimitLayer
Tower layer that applies configured rate limiting.
RateLimitService
Service produced by RateLimitLayer.
RequestContextLayer
Tower layer that inserts request/correlation context into request extensions.
RequestContextService
Service produced by RequestContextLayer.
RequestIdConfig
Typed configuration for validated request ID propagation.
RequestIdLayer
Legacy Tower layer that adds an x-request-id response header when absent.
RequestIdService
Service produced by RequestIdLayer.
RequestScopeLayer
Tower layer that creates one dependency request scope per HTTP request.
RequestScopeService
Service produced by RequestScopeLayer.
RouteMakeSpan
Span maker that records request method, URI, and a stable route label.
SecurityHeadersLayer
Tower layer that adds conservative API security headers to responses.
SecurityHeadersService
Service produced by SecurityHeadersLayer.
TimeoutResponseLayer
Tower layer that maps elapsed inner work to an HTTP timeout response.
TimeoutResponseService
Service produced by TimeoutResponseLayer.
ValidatedRequestIdLayer
Tower layer that validates, generates, stores, and propagates request IDs.
ValidatedRequestIdService
Service produced by ValidatedRequestIdLayer.

Enums§

RequestIdMode
Request ID validation behavior for inbound x-request-id values.

Traits§

HttpMetricsHook
Backend-neutral hook for recording HTTP request metrics.
RateLimitStore
Store adapter used by rate-limit layers.

Functions§

body_limit_layer
Creates a request body limit layer using the declared Content-Length.
catch_panic_layer
Creates a layer that catches panics from the inner service and maps them to a 500 Internal Server Error response.
compression_layer
Creates a gzip response compression layer.
cors_layer
Creates a permissive CORS layer for API development and examples.
cors_origin_layer
Creates a CORS layer for a single explicit API origin.
metrics_layer
Creates a metrics hook layer without a stable route label.
rate_limit_layer
Creates a Tower rate limit layer.
request_context_layer
Creates a Tower layer that enriches RequestContext request extensions.
request_id_layer
Creates the legacy response-only request-id layer.
request_scope_layer
Creates a request-scope layer backed by a shared dependency container.
route_metrics_layer
Creates a metrics hook layer that records a stable route label.
route_trace_layer
Creates an HTTP tracing layer that records a stable route label.
security_headers_layer
Creates a layer that applies conservative API security headers.
streaming_body_limit_layer
Creates a streaming request body limit layer.
timeout_layer
Creates a Tower timeout layer.
timeout_response_layer
Creates a timeout layer that maps elapsed inner work to 408 Request Timeout.
trace_layer
Creates an HTTP tracing layer for requests and responses.
validated_request_id_layer
Creates a validated request ID layer.
webhook_body_limit_layer
Creates a request body limit layer for webhook/raw-body routes.

Type Aliases§

RequestIdPolicy
Compatibility alias for naming request ID validation policy.