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_request_interceptor(&mut self, interceptor: RequestInterceptor)
pub fn add_request_interceptor(&mut self, interceptor: RequestInterceptor)
Appends a request interceptor applied before each request attempt.
§Parameters
interceptor: Request interceptor to append (order is preserved).
Sourcepub fn add_response_interceptor(&mut self, interceptor: ResponseInterceptor)
pub fn add_response_interceptor(&mut self, interceptor: ResponseInterceptor)
Appends a response interceptor applied on successful responses.
§Parameters
interceptor: Response interceptor to append (order is preserved).
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 clear_request_interceptors(&mut self)
pub fn clear_request_interceptors(&mut self)
Removes all registered request interceptors.
Sourcepub fn clear_response_interceptors(&mut self)
pub fn clear_response_interceptors(&mut self)
Removes all registered response interceptors.
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 and returns a unified 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 fn execute_sse_with_reconnect(
&self,
request: HttpRequest,
reconnect_options: SseReconnectOptions,
) -> SseEventStream
pub fn execute_sse_with_reconnect( &self, request: HttpRequest, reconnect_options: SseReconnectOptions, ) -> SseEventStream
Opens an SSE stream and reconnects automatically on retryable stream failures.
Reconnect behavior:
- retryable transport/read failures trigger reconnects;
- optional reconnect on clean EOF (
reconnect_on_eof); Last-Event-IDis set from the latest parsed SSEid:field;- optional use of SSE
retry:as next reconnect delay.
§Parameters
request: SSE request template reused on reconnect.reconnect_options: Reconnect limits and delay policy.
§Returns
SSE event stream yielding events from one or more reconnect sessions.
§Errors
Per-item stream errors include:
- initial stream-open failures (when not reconnectable or retries exhausted);
- SSE protocol errors (non-reconnectable by default);
- transport/read errors after reconnect budget is exhausted.
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