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 usingreqwest- Mock implementations for testing
Required Associated Types§
Required Methods§
Sourcefn stream(
&self,
url: &str,
headers: &[(String, String)],
) -> impl Future<Output = Result<BoxStream<'static, Result<Bytes, Self::Error>>, Self::Error>> + Send
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 fetchheaders- 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.
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.