Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    // Required method
    fn fetch(
        &self,
        req: HttpRequest,
    ) -> BoxFuture<'_, Result<HttpResponse, HttpClientError>>;
}
Expand description

HTTP fetch backend trait.

Implementors must satisfy the following contract:

  • fetch must internally enforce the total timeout from req.timeout (including connect and read body); on timeout, return HttpClientError::Timeout.
  • When req.follow_redirects = true, follow 3xx responses per RFC 7231, up to req.max_redirects hops; exceeding that returns HttpClientError::TooManyRedirects.
  • When reading the body, stop after accumulating req.max_response_bytes and set truncated = true on the response.
  • Any HTTP status (including 4xx/5xx) is considered a success (HttpResponse::status is returned as-is); only transport or decode failures should return Err.

Required Methods§

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§