Skip to main content

HttpBackend

Trait HttpBackend 

Source
pub trait HttpBackend:
    MaybeSend
    + MaybeSync
    + Debug {
    // Required method
    fn execute(&self, request: Request<HttpBody>) -> ExecuteFuture<'_>;
}
Expand description

The swappable HTTP transport: it executes a prepared [http::Request] into an [http::Response], each carrying an HttpBody.

This is the seam the retry adapter, the middleware interceptor, and the WASM build all rest on: implement it to wrap, replace, or retry the execute step without touching URL building, auth, decode, streaming, or pagination. The default ReqwestBackend runs the request on a wrapped reqwest::Client.

Implementations must be MaybeSend + MaybeSync — Send + Sync on native (the Client is shared across tasks), vacuous on wasm32 — and Debug (so 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 execute(&self, request: Request<HttpBody>) -> ExecuteFuture<'_>

Execute a prepared request, yielding the raw response or a transport failure. The request’s URI is absolute. A backend that fails builds its TransportError with the constructor naming the failure’s class, so the runtime’s send maps it to the right super::Error variant.

A request carrying a TotalTimeout extension is bounded by it: from the moment execute is called until the whole response body has been read. A deadline that elapses fails the call, or the body read in progress, with a TransportError::timeout of super::TimeoutKind::Total. The runtime’s send puts the client’s super::ClientConfig::timeout there, so a backend that ignores the extension leaves the call unbounded. ReqwestBackend makes it reqwest’s own request timeout. A backend that executes the request more than once through an inner one bounds each execution, not their sum: super::RetryBackend hands every attempt the same extension and awaits its policy’s backoff between them, so a retried call may take each attempt’s timeout plus the backoffs.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§