Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient: Send + Sync {
    type Error: Error + Send + 'static;

    // Required methods
    fn stream(
        &self,
        url: &str,
        headers: &[(String, String)],
    ) -> impl Future<Output = Result<BoxStream<'static, Result<Bytes, Self::Error>>, Self::Error>> + Send;
    fn head(
        &self,
        url: &str,
    ) -> impl Future<Output = Result<Option<u64>, Self::Error>> + Send;
}
Expand description

Asynchronous HTTP client abstraction.

This trait provides the minimal interface needed for fetching operations. Implementations handle their own redirect following, timeout configuration, and error mapping.

§Implementations

  • ReqwestClient: Production implementation using reqwest
  • Mock implementations for testing

Required Associated Types§

Source

type Error: Error + Send + 'static

Error type for HTTP operations.

Required Methods§

Source

fn stream( &self, url: &str, headers: &[(String, String)], ) -> impl Future<Output = Result<BoxStream<'static, Result<Bytes, Self::Error>>, Self::Error>> + Send

Open a streaming HTTP connection and return the response body as a stream.

§Arguments
  • url - The URL to fetch
  • headers - Custom headers to include with the request
§Returns

A stream of bytes from the response body.

§Errors

Returns an error if the request fails (DNS failure, connection error, HTTP error status, etc.). Implementations should map HTTP errors to a suitable error type.

Source

fn head( &self, url: &str, ) -> impl Future<Output = Result<Option<u64>, Self::Error>> + Send

Query the Content-Length header without downloading the body.

This is used for progress reporting when the total file size is known.

§Arguments
  • url - The URL to query
§Returns

Ok(Some(n)) if Content-Length is present, Ok(None) if absent or using chunked encoding, Err(...) if the request fails.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§