pub trait HttpClient: MaybeSendSync {
// Required method
fn execute<'life0, 'async_trait>(
&'life0 self,
request: HttpRequest,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided methods
fn supports_streaming(&self) -> bool { ... }
fn execute_streaming(
&self,
_request: HttpRequest,
) -> Result<StreamingHttpResponse, Error> { ... }
fn supports_upload_streaming(&self) -> bool { ... }
fn execute_upload(
&self,
_request: HttpRequest,
_body: Box<dyn Read + Send>,
_content_length: u64,
) -> Result<HttpResponse, Error> { ... }
fn resource_report(&self) -> Option<HttpResourceReport> { ... }
}Expand description
Trait for executing HTTP requests in a runtime-agnostic way.
A completed exchange is Ok, whatever the status. Err means the
exchange never happened — DNS, connect, TLS, timeout, a body that broke the
declared cap. Implementations MUST NOT map 4xx/5xx to an error: media
download and upload read status_code to tell a stale media-auth token
(401/403) and an expired URL (404/410) — both of which need a refreshed
media connection before the retry — apart from a host-level failure that
should simply move to the next CDN host. An implementation that hides the
status behind an opaque error makes every one of those retries repeat the
same dead auth token. Some HTTP crates default the other way: ureq’s
http_status_as_error is the known case.
Required Methods§
Sourcefn execute<'life0, 'async_trait>(
&'life0 self,
request: HttpRequest,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
request: HttpRequest,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Executes a given HTTP request and returns the response, non-2xx included.
Provided Methods§
Sourcefn supports_streaming(&self) -> bool
fn supports_streaming(&self) -> bool
Whether this client supports synchronous streaming downloads.
Sourcefn execute_streaming(
&self,
_request: HttpRequest,
) -> Result<StreamingHttpResponse, Error>
fn execute_streaming( &self, _request: HttpRequest, ) -> Result<StreamingHttpResponse, Error>
Synchronous streaming variant — returns a reader over the response body. Must be called from a blocking context.
Sourcefn supports_upload_streaming(&self) -> bool
fn supports_upload_streaming(&self) -> bool
Whether this client can stream a request body from a reader (upload).
Sourcefn execute_upload(
&self,
_request: HttpRequest,
_body: Box<dyn Read + Send>,
_content_length: u64,
) -> Result<HttpResponse, Error>
fn execute_upload( &self, _request: HttpRequest, _body: Box<dyn Read + Send>, _content_length: u64, ) -> Result<HttpResponse, Error>
Synchronous streaming upload: send body (exactly content_length bytes)
as the request body. Implementations MUST set an explicit Content-Length
rather than chunked transfer-encoding. Any body set on request is
ignored. Must be called from a blocking context.
Sourcefn resource_report(&self) -> Option<HttpResourceReport>
fn resource_report(&self) -> Option<HttpResourceReport>
Best-effort per-session footprint of this client: idle connection-pool
buffers plus any in-flight download/media buffering the impl can see.
None by default; ureq/reqwest-backed clients report what their
(limited) introspection allows. Media downloads are a real transient-RAM
source, so a coarse estimate is still worth reporting.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".