Skip to main content

HttpClient

Struct HttpClient 

Source
pub struct HttpClient { /* private fields */ }
Expand description

High-level HTTP client that applies options, header injection, logging, and timeouts.

Implementations§

Source§

impl HttpClient

Source

pub fn options(&self) -> &HttpClientOptions

Returns a reference to the client options (timeouts, proxy, logging, etc.).

§Returns

Immutable borrow of HttpClientOptions.

Source

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.

Source

pub fn add_async_header_injector(&mut self, injector: AsyncHeaderInjector)

Appends an async header injector whose mutation runs after sync injectors.

§Parameters
  • injector: Async injector to append (order is preserved).
§Returns

Nothing.

Source

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).
Source

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).
Source

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.

Source

pub fn add_headers<'a, I>(&mut self, headers: I) -> HttpResult<&mut Self>
where I: IntoIterator<Item = (&'a str, &'a str)>,

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).

Source

pub fn clear_header_injectors(&mut self)

Removes all registered header injectors.

§Returns

Nothing.

Source

pub fn clear_async_header_injectors(&mut self)

Removes all registered async header injectors.

§Returns

Nothing.

Source

pub fn clear_request_interceptors(&mut self)

Removes all registered request interceptors.

Source

pub fn clear_response_interceptors(&mut self)

Removes all registered response interceptors.

Source

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
§Returns

A fresh HttpRequestBuilder not yet tied to this client until HttpRequestBuilder::build and HttpClient::execute.

Source

pub async fn execute(&self, request: HttpRequest) -> HttpResult<HttpResponse>

Sends the request and returns a unified HttpResponse.

§Parameters
  • request: Built request (URL resolved against base_url if 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.
Source

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-ID is set from the latest parsed SSE id: 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

Source§

fn clone(&self) -> HttpClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the client for debugging (exposes options and injectors; omits the backend client).

§Parameters
  • f: Destination formatter.
§Returns

fmt::Result from writing the debug struct.

§Errors

Returns an error if formatting to f fails.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more