pub struct RequestIdConfig { /* private fields */ }Expand description
Typed configuration for validated request ID propagation.
The default production config uses the x-request-id header, strict inbound
validation, and UUID v4 generation. Custom generators are accepted, but their
output must be a valid HTTP header value because generated IDs are inserted
into request headers, request extensions, and response headers. If a custom
generator returns an invalid header value, the middleware returns a stable
500 Internal Server Error response with code
invalid_generated_request_id instead of panicking or calling the inner
service.
Implementations§
Source§impl RequestIdConfig
impl RequestIdConfig
Sourcepub fn production() -> Self
pub fn production() -> Self
Creates a production request ID policy.
Defaults:
- header:
x-request-id - inbound validation:
RequestIdMode::Strict - generated IDs: UUID v4 strings
In strict mode, a present but malformed inbound ID is rejected with
400 Bad Request. Missing IDs are generated and accepted.
Sourcepub fn development() -> Self
pub fn development() -> Self
Creates a development request ID policy.
Development uses the same x-request-id header and UUID v4 generator as
production, but switches to RequestIdMode::Permissive. Valid inbound
UUID v4 IDs are propagated; malformed inbound IDs are replaced with
generated UUID v4 IDs instead of returning 400.
Sourcepub fn header_name(self, header_name: HeaderName) -> Self
pub fn header_name(self, header_name: HeaderName) -> Self
Sets the request ID header name.
Sourcepub fn mode(self, mode: RequestIdMode) -> Self
pub fn mode(self, mode: RequestIdMode) -> Self
Sets request ID validation behavior for present inbound IDs.
Sourcepub fn generator(
self,
generator: impl Fn() -> String + Send + Sync + 'static,
) -> Self
pub fn generator( self, generator: impl Fn() -> String + Send + Sync + 'static, ) -> Self
Replaces the request ID generator.
RequestIdConfig::production and RequestIdConfig::development use
UUID v4 strings. If you provide a custom generator, keep it deterministic
enough for your tests and ensure it returns values that can be stored in
an HTTP header. Invalid generated header values return a structured
framework error response before the request reaches the inner service.
Sourcepub fn header(&self) -> &HeaderName
pub fn header(&self) -> &HeaderName
Returns the configured request ID header name.
Sourcepub const fn validation_mode(&self) -> RequestIdMode
pub const fn validation_mode(&self) -> RequestIdMode
Returns the configured validation mode.
Trait Implementations§
Source§impl Clone for RequestIdConfig
impl Clone for RequestIdConfig
Source§fn clone(&self) -> RequestIdConfig
fn clone(&self) -> RequestIdConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more