Skip to main content

ClientBuilder

Struct ClientBuilder 

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

A builder for constructing a Client with custom configuration.

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

Create a new ClientBuilder with default settings.

Source

pub fn pool_max_idle_per_host(self, n: usize) -> Self

Set the maximum number of idle connections per host in the pool.

Source

pub fn pool_idle_timeout(self, duration: Duration) -> Self

Set the idle timeout for pooled connections.

Source

pub fn connect_timeout(self, duration: Duration) -> Self

Set the TCP connect timeout.

Source

pub fn read_timeout(self, duration: Duration) -> Self

Set the response read timeout.

Source

pub fn redirect_policy(self, policy: RedirectPolicy) -> Self

Set the redirect policy.

Source

pub fn retry_policy(self, policy: RetryPolicy) -> Self

Set the retry policy.

Source

pub fn default_headers(self, headers: HeaderMap) -> Self

Set default headers to include on every request.

Source

pub fn user_agent(self, agent: impl Into<String>) -> Self

Set the User-Agent header for all requests.

Source

pub fn with_decompression(self, enabled: bool) -> Self

Enable or disable automatic response decompression.

When enabled the client adds Accept-Encoding: gzip, deflate to outgoing requests and transparently decompresses the response body based on the Content-Encoding header (requires decompression feature).

Source

pub fn with_middleware<M: ClientMiddleware + 'static>(self, m: M) -> Self

Register a request/response middleware interceptor.

Middleware is invoked in registration order: before_request fires in FIFO order before the first network attempt; after_response fires in FIFO order after a successful final response.

Multiple calls to this method append to the middleware stack.

§Example
use oxihttp_client::{Client, middleware::LoggingMiddleware};

let client = Client::builder()
    .with_middleware(LoggingMiddleware::new("api"))
    .build()
    .expect("client build");
Source

pub fn with_layer<M: ClientMiddleware + 'static>(self, m: M) -> Self

Alias for ClientBuilder::with_middleware.

Provided so that callers familiar with the tower::Layer terminology can use the same name. This does not accept a tower::Layer; for a full tower Service composition see the tower_compat module docs.

Configure the client to use the given shared cookie jar for automatic cookie management.

Configure the client to create and use a fresh cookie jar automatically.

Source

pub fn with_http2_settings(self, settings: Http2Settings) -> Self

Set HTTP/2 connection tuning parameters.

Source

pub fn with_tcp_nodelay(self, nodelay: bool) -> Self

Enable or disable TCP_NODELAY on all outgoing connections.

Source

pub fn with_tcp_keepalive(self, duration: Duration) -> Self

Set the TCP keepalive idle time for all outgoing connections.

Source

pub fn with_resolver<R: DnsResolver>(self, r: R) -> Self

Set a custom DNS resolver for all connections made by this client.

After calling this, use ClientBuilder::build_with_resolver (plain HTTP) or [ClientBuilder::build_https_with_resolver] (TLS) to construct the client.

Source

pub fn with_http_proxy(self, uri: Uri) -> Self

Route all requests through an HTTP CONNECT proxy.

Call build_proxy() (plain HTTP target) or build_proxy_https() (HTTPS target, requires tls feature) after setting this.

Source

pub fn build_proxy(self) -> Result<Client<ProxyConnector>, OxiHttpError>

Build a plain-HTTP Client routed through an HTTP CONNECT proxy.

with_http_proxy() must have been called before this.

Source

pub fn build(self) -> Result<Client, OxiHttpError>

Build a plain HTTP Client (no TLS).

Source

pub fn build_with_resolver(self) -> Result<ResolverClient, OxiHttpError>

Build a plain HTTP Client using a custom DNS resolver.

ClientBuilder::with_resolver must be called before this.

Trait Implementations§

Source§

impl Debug for ClientBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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, 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