pub struct HttpClient { /* private fields */ }Expand description
High-level HTTP client: default headers, injectors, interceptors, logging, timeouts, and optional per-request retry.
Clone is shallow and cheap enough for typical use (including passing into
retry closures); cloning does not duplicate the underlying connection pool
beyond what reqwest::Client already shares.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn options(&self) -> &HttpClientOptions
pub fn options(&self) -> &HttpClientOptions
Returns a reference to the client-wide options (timeouts, proxy, logging, default headers, retry defaults, etc.).
§Returns
Immutable borrow of HttpClientOptions. Never None; always the
options installed on this client.
Sourcepub fn add_header_injector(&mut self, injector: HttpHeaderInjector)
pub fn add_header_injector(&mut self, injector: HttpHeaderInjector)
Appends a HttpHeaderInjector so its mutation function runs on every
request. Mutates self in place.
§Parameters
injector: Injector to append (order is preserved).
Sourcepub fn add_async_header_injector(&mut self, injector: AsyncHttpHeaderInjector)
pub fn add_async_header_injector(&mut self, injector: AsyncHttpHeaderInjector)
Appends an async header injector whose mutation runs after sync injectors.
Mutates self in place.
§Parameters
injector: Async injector to append (order is preserved).
Sourcepub fn add_request_interceptor(&mut self, interceptor: HttpRequestInterceptor)
pub fn add_request_interceptor(&mut self, interceptor: HttpRequestInterceptor)
Appends a request interceptor run before each send attempt (including
each retry attempt). Mutates self in place.
§Parameters
interceptor: Request interceptor to append (order is preserved).
Sourcepub fn add_response_interceptor(&mut self, interceptor: HttpResponseInterceptor)
pub fn add_response_interceptor(&mut self, interceptor: HttpResponseInterceptor)
Appends a response interceptor run only after a successful HTTP status
(after the internal execute_once step) and before response body logging.
Mutates self in place.
§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(&mut self, headers: &[(&str, &str)]) -> HttpResult<&mut Self>
pub fn add_headers(&mut self, headers: &[(&str, &str)]) -> 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)
Clears all synchronous header injectors. Mutates self in place.
Sourcepub fn clear_async_header_injectors(&mut self)
pub fn clear_async_header_injectors(&mut self)
Clears all async header injectors. Mutates self in place.
Sourcepub fn clear_request_interceptors(&mut self)
pub fn clear_request_interceptors(&mut self)
Clears all request interceptors. Mutates self in place.
Sourcepub fn clear_response_interceptors(&mut self)
pub fn clear_response_interceptors(&mut self)
Clears all response interceptors. Mutates self in place.
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 new HttpRequestBuilder borrowing this client for defaults; it is
not sent until built and passed to HttpClient::execute (or related
APIs).
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.
Chooses retry vs single attempt from resolved HttpRetryOptions for
this request. Performs network I/O and may await the internal
execute_once path
multiple times with backoff between attempts when retry is enabled.
§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)when any attempt fails for URL/header validation, cancellation, interceptor failure, transport/timeout, non-success status, or when the retry executor aborts or exceeds limits.
Sourcepub fn execute_sse_with_reconnect(
&self,
request: HttpRequest,
options: SseReconnectOptions,
) -> SseEventStream
pub fn execute_sse_with_reconnect( &self, request: HttpRequest, 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.options: Reconnect limits and delay policy.
§Returns
SSE event stream yielding events from one or more reconnect sessions.
§Errors
Stream items are Result; Err covers per-item failures such as:
- 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.
§Side effects
Performs repeated HTTP requests and reads on reconnect; may sleep between attempts according to reconnect options.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HttpClient
impl Debug for HttpClient
Auto Trait Implementations§
impl Freeze for HttpClient
impl !RefUnwindSafe for HttpClient
impl Send for HttpClient
impl Sync for HttpClient
impl Unpin for HttpClient
impl UnsafeUnpin for HttpClient
impl !UnwindSafe for HttpClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
impl<T, D> IntoConfigDefault<T> for Dwhere
D: IntoValueDefault<T>,
Source§fn into_config_default(self) -> T
fn into_config_default(self) -> T
T.