pub struct ClientConfig { /* private fields */ }Expand description
Runtime configuration for an HTTP Client.
The configuration is stored in SharedCfg and can be
supplied before constructing a client with Client::with_config
or ClientBuilder::build.
Implementations§
Source§impl ClientConfig
impl ClientConfig
Sourcepub fn new() -> ClientConfig
pub fn new() -> ClientConfig
Creates an HTTP client configuration with default values.
Sourcepub fn response_timeout(&self) -> Millis
pub fn response_timeout(&self) -> Millis
Returns the response-header timeout.
Sourcepub fn response_payload_limit(&self) -> usize
pub fn response_payload_limit(&self) -> usize
Returns the maximum response payload size.
A value of zero disables the limit.
Sourcepub fn response_payload_timeout(&self) -> Millis
pub fn response_payload_timeout(&self) -> Millis
Returns the timeout for reading a complete response payload.
Sourcepub fn h1_connection_limit(&self) -> usize
pub fn h1_connection_limit(&self) -> usize
Returns the maximum number of simultaneous HTTP/1 connections per connection pool.
Sourcepub fn h2_connection_limit(&self) -> usize
pub fn h2_connection_limit(&self) -> usize
Returns the maximum number of HTTP/2 connections per host.
Sourcepub fn h2_max_streams(&self) -> u32
pub fn h2_max_streams(&self) -> u32
Returns the maximum number of concurrent requests per HTTP/2 connection.
Sourcepub fn h2_keepalive(&self) -> Seconds
pub fn h2_keepalive(&self) -> Seconds
Returns the keep-alive period for idle HTTP/2 connections.
Sourcepub fn h2_lifetime(&self) -> Seconds
pub fn h2_lifetime(&self) -> Seconds
Returns the maximum lifetime of an HTTP/2 connection.
Sourcepub fn set_h1_connection_limit(self, limit: usize) -> Self
pub fn set_h1_connection_limit(self, limit: usize) -> Self
Sets the maximum number of simultaneous connections per connection pool.
The limit is shared by all hosts. A client keeps separate pools for
plain and TLS connections, and each pool has its own limit. The limit
counts HTTP/1 connections in use and connections being opened;
HTTP/2 connections are limited by
set_h2_connection_limit. A value of
zero disables the limit. The default is 8.
Sourcepub fn set_h1_keepalive<T: Into<Seconds>>(self, dur: T) -> Self
pub fn set_h1_keepalive<T: Into<Seconds>>(self, dur: T) -> Self
Sets the keep-alive period for idle pooled HTTP/1 connections.
HTTP/2 connections use set_h2_keepalive.
A pooled connection that has been idle longer than this period is not
reused. Expiration is checked lazily, when a connection for the same
host is next requested; the expired connection is closed at that point.
A zero duration disables the idle check; use
ClientRequest::force_close to
avoid reusing a connection. The default is 15 seconds.
Sourcepub fn set_h1_lifetime<T: Into<Seconds>>(self, dur: T) -> Self
pub fn set_h1_lifetime<T: Into<Seconds>>(self, dur: T) -> Self
Sets the maximum lifetime of a pooled HTTP/1 connection.
HTTP/2 connections use set_h2_lifetime.
A connection older than this period is not reused, regardless of how
recently it was used. Like the keep-alive period, this is checked when a
connection for the same host is next requested. A zero duration disables
the limit. The default is 75 seconds.
Sourcepub fn set_h2_connection_limit(self, limit: usize) -> Self
pub fn set_h2_connection_limit(self, limit: usize) -> Self
Sets the maximum number of HTTP/2 connections per host.
HTTP/2 connections are shared by concurrent requests. A new connection
to a host is opened only when every existing HTTP/2 connection to that
host has reached its stream limit, see
set_h2_max_streams. When the limit is
reached, requests wait for a free stream.
Requests on established HTTP/2 connections do not count against
set_h1_connection_limit; opening a new
connection does, because the protocol is not known until the
connection is established. A value of zero disables the limit.
The default is 16.
Sourcepub fn set_h2_max_streams(self, limit: u32) -> Self
pub fn set_h2_max_streams(self, limit: u32) -> Self
Sets the maximum number of concurrent requests per HTTP/2 connection.
The peer’s SETTINGS_MAX_CONCURRENT_STREAMS also applies; the lower of
the two is used. A value of zero uses only the peer’s setting.
The default is 100.
Sourcepub fn set_h2_keepalive<T: Into<Seconds>>(self, dur: T) -> Self
pub fn set_h2_keepalive<T: Into<Seconds>>(self, dur: T) -> Self
Sets the keep-alive period for idle HTTP/2 connections.
An HTTP/2 connection is idle when it has no in-flight requests; the period is measured from the completion of its last request, including the response payload. An idle connection older than this period is closed when a connection for the same host is next requested. A zero duration disables the idle check. The default is 60 seconds.
Sourcepub fn set_h2_lifetime<T: Into<Seconds>>(self, dur: T) -> Self
pub fn set_h2_lifetime<T: Into<Seconds>>(self, dur: T) -> Self
Sets the maximum lifetime of an HTTP/2 connection.
An HTTP/2 connection older than this period is not used for new requests and is closed gracefully, after its in-flight requests complete. This is checked when a connection for the same host is next requested. A zero duration disables the limit. The default is 1 hour.
Sourcepub fn set_response_timeout<T: Into<Millis>>(self, timeout: T) -> Self
pub fn set_response_timeout<T: Into<Millis>>(self, timeout: T) -> Self
Sets the response-header timeout.
The timeout covers receiving the response head after the request has been sent. Connecting and sending the request are not included. A zero duration disables the timeout. The default is 5 seconds.
Sourcepub fn disable_timeout(self) -> Self
pub fn disable_timeout(self) -> Self
Disables the response-header timeout.
This is the same as set_response_timeout(Millis::ZERO).
Sourcepub fn set_response_payload_limit(self, limit: usize) -> Self
pub fn set_response_payload_limit(self, limit: usize) -> Self
Sets the maximum size of a buffered response payload.
The default is 256 KiB. A value of zero disables the limit.
Sourcepub fn set_response_payload_timeout<T: Into<Millis>>(self, timeout: T) -> Self
pub fn set_response_payload_timeout<T: Into<Millis>>(self, timeout: T) -> Self
Sets the timeout for reading a complete response payload.
The default is 10 seconds. A zero duration disables the timeout.
Sourcepub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
pub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>where
HeaderName: TryFrom<K>,
HeaderValue: TryFrom<V>,
<HeaderName as TryFrom<K>>::Error: Into<HttpError>,
<HeaderValue as TryFrom<V>>::Error: Into<HttpError>,
Adds a header to every request.
A request-specific header with the same name takes precedence.
Sourcepub fn set_basic_auth<U>(
self,
username: U,
password: Option<&str>,
) -> Result<Self, HttpError>where
U: Display,
pub fn set_basic_auth<U>(
self,
username: U,
password: Option<&str>,
) -> Result<Self, HttpError>where
U: Display,
Sets a client-wide HTTP Basic authentication header.
Replaces any previously configured Authorization header.
Sourcepub fn set_bearer_auth<T>(self, token: T) -> Result<Self, HttpError>where
T: Display,
pub fn set_bearer_auth<T>(self, token: T) -> Result<Self, HttpError>where
T: Display,
Sets a client-wide HTTP Bearer authentication header.
Replaces any previously configured Authorization header.