pub struct ClientBuilder { /* private fields */ }Expand description
A builder for constructing a Client with custom configuration.
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn pool_max_idle_per_host(self, n: usize) -> Self
pub fn pool_max_idle_per_host(self, n: usize) -> Self
Set the maximum number of idle connections per host in the pool.
Sourcepub fn pool_idle_timeout(self, duration: Duration) -> Self
pub fn pool_idle_timeout(self, duration: Duration) -> Self
Set the idle timeout for pooled connections.
Sourcepub fn connect_timeout(self, duration: Duration) -> Self
pub fn connect_timeout(self, duration: Duration) -> Self
Set the TCP connect timeout.
Sourcepub fn read_timeout(self, duration: Duration) -> Self
pub fn read_timeout(self, duration: Duration) -> Self
Set the response read timeout.
Sourcepub fn redirect_policy(self, policy: RedirectPolicy) -> Self
pub fn redirect_policy(self, policy: RedirectPolicy) -> Self
Set the redirect policy.
Sourcepub fn retry_policy(self, policy: RetryPolicy) -> Self
pub fn retry_policy(self, policy: RetryPolicy) -> Self
Set the retry policy.
Sourcepub fn default_headers(self, headers: HeaderMap) -> Self
pub fn default_headers(self, headers: HeaderMap) -> Self
Set default headers to include on every request.
Sourcepub fn user_agent(self, agent: impl Into<String>) -> Self
pub fn user_agent(self, agent: impl Into<String>) -> Self
Set the User-Agent header for all requests.
Sourcepub fn with_decompression(self, enabled: bool) -> Self
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).
Sourcepub fn with_middleware<M: ClientMiddleware + 'static>(self, m: M) -> Self
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");Sourcepub fn with_layer<M: ClientMiddleware + 'static>(self, m: M) -> Self
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.
Sourcepub fn with_http2_settings(self, settings: Http2Settings) -> Self
pub fn with_http2_settings(self, settings: Http2Settings) -> Self
Set HTTP/2 connection tuning parameters.
Sourcepub fn with_tcp_nodelay(self, nodelay: bool) -> Self
pub fn with_tcp_nodelay(self, nodelay: bool) -> Self
Enable or disable TCP_NODELAY on all outgoing connections.
Sourcepub fn with_tcp_keepalive(self, duration: Duration) -> Self
pub fn with_tcp_keepalive(self, duration: Duration) -> Self
Set the TCP keepalive idle time for all outgoing connections.
Sourcepub fn with_resolver<R: DnsResolver>(self, r: R) -> Self
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.
Sourcepub fn with_http_proxy(self, uri: Uri) -> Self
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.
Sourcepub fn build_proxy(self) -> Result<Client<ProxyConnector>, OxiHttpError>
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.
Sourcepub fn build(self) -> Result<Client, OxiHttpError>
pub fn build(self) -> Result<Client, OxiHttpError>
Build a plain HTTP Client (no TLS).
Sourcepub fn build_with_resolver(self) -> Result<ResolverClient, OxiHttpError>
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.