Skip to main content

ClientMiddleware

Trait ClientMiddleware 

Source
pub trait ClientMiddleware: Send + Sync {
    // Required methods
    fn before_request(&self, ctx: &RequestContext<'_>);
    fn after_response(&self, ctx: &ResponseContext);
}
Expand description

A request/response interceptor that can observe (but not modify) each HTTP round-trip.

Both callbacks receive a context struct describing the relevant phase. The before_request hook fires once per send() call, immediately before the first attempt. The after_response hook fires once after the final successful response (or after the last failed attempt returns an error, though in error cases after_response is not called — see ClientMiddleware::after_error for that).

Required Methods§

Source

fn before_request(&self, ctx: &RequestContext<'_>)

Called immediately before the first network attempt.

Source

fn after_response(&self, ctx: &ResponseContext)

Called after a successful response is obtained (including after retries).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§