pub struct RequestIdLayer { /* private fields */ }Expand description
Middleware that ensures every request/response pair carries a stable correlation ID.
- If the incoming request already has the header (e.g. set by an upstream gateway, load balancer, or calling service), that exact value is kept and echoed back unchanged — this lets one ID follow a request across multiple services instead of getting a new one at each hop.
- Otherwise, a fresh ID is generated with
generate_request_idand injected into the request before it reaches your handler, so handlers can read it like any other header. - The same value is always set on the response, so the caller can log it too — even if it arrived with no ID and this middleware generated one.
Implementations§
Trait Implementations§
Source§impl Default for RequestIdLayer
impl Default for RequestIdLayer
Source§impl Middleware for RequestIdLayer
impl Middleware for RequestIdLayer
Source§fn accepts_streamed_body(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn accepts_streamed_body( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
Headers only: a streamed body passes through untouched.
Source§fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
fn runs_inline(&self, _request: &Request, _connection: &ConnectionInfo) -> bool
In-memory only: safe on the event loop.
fn handle( &self, request: &Request, connection: &ConnectionInfo, next: &dyn Application, ) -> Result<Response, String>
Source§fn is_passthrough(
&self,
_request: &Request,
_connection: &ConnectionInfo,
) -> bool
fn is_passthrough( &self, _request: &Request, _connection: &ConnectionInfo, ) -> bool
true when handle would do nothing for request but call next
(e.g. a rate limit that isn’t configured). A WithMiddleware stack
offers the inner application’s execute_async only if every layer
passes the request through. Default false.Auto Trait Implementations§
impl Freeze for RequestIdLayer
impl RefUnwindSafe for RequestIdLayer
impl Send for RequestIdLayer
impl Sync for RequestIdLayer
impl Unpin for RequestIdLayer
impl UnsafeUnpin for RequestIdLayer
impl UnwindSafe for RequestIdLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more