Skip to main content

ClientConfig

Struct ClientConfig 

Source
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

Source

pub fn new() -> ClientConfig

Creates an HTTP client configuration with default values.

Source

pub fn headers(&self) -> &HeaderMap

Returns the headers added to every request.

Source

pub fn response_timeout(&self) -> Millis

Returns the response-header timeout.

Source

pub fn response_payload_limit(&self) -> usize

Returns the maximum response payload size.

A value of zero disables the limit.

Source

pub fn response_payload_timeout(&self) -> Millis

Returns the timeout for reading a complete response payload.

Source

pub fn h1_connection_limit(&self) -> usize

Returns the maximum number of simultaneous HTTP/1 connections per connection pool.

Source

pub fn h2_connection_limit(&self) -> usize

Returns the maximum number of HTTP/2 connections per host.

Source

pub fn h2_max_streams(&self) -> u32

Returns the maximum number of concurrent requests per HTTP/2 connection.

Source

pub fn h2_keepalive(&self) -> Seconds

Returns the keep-alive period for idle HTTP/2 connections.

Source

pub fn h2_lifetime(&self) -> Seconds

Returns the maximum lifetime of an HTTP/2 connection.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn disable_timeout(self) -> Self

Disables the response-header timeout.

This is the same as set_response_timeout(Millis::ZERO).

Source

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.

Source

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.

Source

pub fn set_header<K, V>(self, key: K, value: V) -> Result<Self, HttpError>

Adds a header to every request.

A request-specific header with the same name takes precedence.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Configuration for ClientConfig

Source§

const NAME: &str = "Http client configuration"

Human-readable configuration name used in diagnostics.
Source§

fn ctx(&self) -> &CfgContext

Returns the shared context associated with this value.
Source§

fn set_ctx(&mut self, ctx: CfgContext)

Associates this value with a shared configuration context.
Source§

impl Debug for ClientConfig

Source§

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

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

impl Default for ClientConfig

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