pub struct HttpClient { /* private fields */ }Expand description
High-level HTTP client that applies options, header injection, logging, and timeouts.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn options(&self) -> &HttpClientOptions
pub fn options(&self) -> &HttpClientOptions
Returns a reference to the client options (timeouts, proxy, logging, etc.).
§Returns
Immutable borrow of HttpClientOptions.
Sourcepub fn add_header_injector(&mut self, injector: HeaderInjector)
pub fn add_header_injector(&mut self, injector: HeaderInjector)
Appends a HeaderInjector so its mutation function runs on every
request.
§Parameters
injector: Injector to append (order is preserved).
§Returns
Nothing.
Sourcepub fn add_async_header_injector(&mut self, injector: AsyncHeaderInjector)
pub fn add_async_header_injector(&mut self, injector: AsyncHeaderInjector)
Sourcepub fn add_header(&mut self, name: &str, value: &str) -> HttpResult<&mut Self>
pub fn add_header(&mut self, name: &str, value: &str) -> HttpResult<&mut Self>
Validates and adds one client-level default header.
The header is applied to every request before header injectors and request-level headers.
§Parameters
name: Header name.value: Header value.
§Returns
Ok(self) after the header is stored.
§Errors
Returns HttpError when the header name or value is invalid.
Sourcepub fn add_headers<'a, I>(&mut self, headers: I) -> HttpResult<&mut Self>
pub fn add_headers<'a, I>(&mut self, headers: I) -> HttpResult<&mut Self>
Validates and adds many client-level default headers atomically.
If any input pair is invalid, no header from this batch is applied.
§Parameters
headers: Iterator of(name, value)pairs.
§Returns
Ok(self) after all headers are stored.
§Errors
Returns HttpError when any name/value pair is invalid (nothing from
this call is applied).
Sourcepub fn clear_header_injectors(&mut self)
pub fn clear_header_injectors(&mut self)
Sourcepub fn clear_async_header_injectors(&mut self)
pub fn clear_async_header_injectors(&mut self)
Sourcepub fn request(&self, method: Method, path: &str) -> HttpRequestBuilder
pub fn request(&self, method: Method, path: &str) -> HttpRequestBuilder
Starts building an HttpRequest with the given method and path
(relative or absolute URL string).
§Parameters
method: HTTP verb (GET, POST, …).path: Path relative toHttpClientOptions::base_urlor a full URL string.
§Returns
A fresh HttpRequestBuilder not yet tied to this client until
HttpRequestBuilder::build and HttpClient::execute.
Sourcepub async fn execute(&self, request: HttpRequest) -> HttpResult<HttpResponse>
pub async fn execute(&self, request: HttpRequest) -> HttpResult<HttpResponse>
Sends the request, reads the full response body, logs per options, and
returns a buffered HttpResponse.
§Parameters
request: Built request (URL resolved againstbase_urlif path is not absolute).
§Returns
Ok(HttpResponse)when the HTTP status is success (http::StatusCode::is_success).Err(HttpError)on URL/header errors, transport failure, timeout, or non-success status.
Sourcepub async fn execute_stream(
&self,
request: HttpRequest,
) -> HttpResult<HttpStreamResponse>
pub async fn execute_stream( &self, request: HttpRequest, ) -> HttpResult<HttpStreamResponse>
Sends the request and returns headers plus a byte stream without buffering the full body.
§Parameters
request: Same asHttpClient::execute.
§Returns
Ok(HttpStreamResponse)with a stream that applies read timeout per options.Err(HttpError)before the stream starts (same cases asHttpClient::executefor the initial response).
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more