Skip to main content

Middleware

Trait Middleware 

Source
pub trait Middleware:
    MaybeSend
    + MaybeSync
    + Debug {
    // Required method
    fn handle<'a>(
        &'a self,
        request: Request<HttpBody>,
        next: Next<'a>,
    ) -> ExecuteFuture<'a>;
}
Expand description

One link in the interceptor chain: it observes/modifies a request on the way in, calls Next::run to proceed (eventually reaching the transport), and observes/modifies the [http::Response] on the way out — or returns early to short-circuit.

Implementations must be MaybeSend + MaybeSync — Send + Sync on native (the Client is shared across tasks), vacuous on wasm32 — and Debug (so MiddlewareBackend — and thus super::ClientCore — stays Debug). The returned future is manually boxed so the trait is object-safe without an async-trait dependency.

Required Methods§

Source

fn handle<'a>( &'a self, request: Request<HttpBody>, next: Next<'a>, ) -> ExecuteFuture<'a>

Handle a request. Call next.run(request) to proceed to the rest of the chain (eventually the transport), or return a response without calling it to short-circuit. May inspect/modify the request before and the [http::Response] after.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§