pub struct HttpClientConfig { /* private fields */ }Expand description
Reusable configuration for constructing reqwest::Client instances.
Unlike reqwest::ClientBuilder, HttpClientConfig is Clone and can be
replayed whenever a super::SwappableClient rebuilds its underlying clients.
Request-specific headers (such as per-mirror X-KEY or per-request bearer
tokens) should be attached on the request or source layer rather than placed
in Self::default_headers when a client is shared across origins.
Implementations§
Source§impl HttpClientConfig
impl HttpClientConfig
Sourcepub fn user_agent(self, user_agent: impl Into<String>) -> Self
pub fn user_agent(self, user_agent: impl Into<String>) -> Self
Sets the User-Agent header value sent by built clients.
Sourcepub fn without_user_agent(self) -> Self
pub fn without_user_agent(self) -> Self
Clears the User-Agent header so reqwest does not send a default one.
Sourcepub fn default_headers(self, headers: HeaderMap) -> Self
pub fn default_headers(self, headers: HeaderMap) -> Self
Replaces the default headers attached to every request made by built clients.
Sourcepub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn default_header(self, name: HeaderName, value: HeaderValue) -> Self
Inserts a single default header attached to every request made by built clients.
Sourcepub fn connect_timeout(self, timeout: Option<Duration>) -> Self
pub fn connect_timeout(self, timeout: Option<Duration>) -> Self
Sets the TCP/TLS connect timeout. Pass None to disable it.
Sourcepub fn read_timeout(self, timeout: Option<Duration>) -> Self
pub fn read_timeout(self, timeout: Option<Duration>) -> Self
Sets the per-read inactivity timeout. Pass None to disable it.
Sourcepub fn timeout(self, timeout: Option<Duration>) -> Self
pub fn timeout(self, timeout: Option<Duration>) -> Self
Sets a total request timeout. Pass None to disable it.
Leave this as None when sharing the client with streaming downloads so
large transfers are bounded by Self::read_timeout instead.
Sourcepub fn proxies(self, proxies: impl IntoIterator<Item = Proxy>) -> Self
pub fn proxies(self, proxies: impl IntoIterator<Item = Proxy>) -> Self
Replaces all configured proxy rules.
Sourcepub fn no_proxy(self, no_proxy: bool) -> Self
pub fn no_proxy(self, no_proxy: bool) -> Self
Disables system proxy discovery when no_proxy is true.
Sourcepub fn customize<F>(self, customizer: F) -> Self
pub fn customize<F>(self, customizer: F) -> Self
Registers a reusable hook that customizes the underlying reqwest::ClientBuilder.
Calling this method multiple times composes the hooks in registration order.
Sourcepub fn user_agent_value(&self) -> Option<&str>
pub fn user_agent_value(&self) -> Option<&str>
Returns the configured User-Agent, if any.
Sourcepub fn default_headers_map(&self) -> &HeaderMap
pub fn default_headers_map(&self) -> &HeaderMap
Returns the configured default headers.
Sourcepub fn connect_timeout_value(&self) -> Option<Duration>
pub fn connect_timeout_value(&self) -> Option<Duration>
Returns the configured connect timeout.
Sourcepub fn read_timeout_value(&self) -> Option<Duration>
pub fn read_timeout_value(&self) -> Option<Duration>
Returns the configured read timeout.
Sourcepub fn timeout_value(&self) -> Option<Duration>
pub fn timeout_value(&self) -> Option<Duration>
Returns the configured total request timeout.
Sourcepub fn is_no_proxy(&self) -> bool
pub fn is_no_proxy(&self) -> bool
Returns whether system proxy discovery is disabled.
Sourcepub fn builder(&self) -> ClientBuilder
pub fn builder(&self) -> ClientBuilder
Produces a fresh reqwest::ClientBuilder with this configuration applied.
Sourcepub fn build(&self) -> Result<Client>
pub fn build(&self) -> Result<Client>
Builds a standard reqwest::Client from this configuration.
Sourcepub fn build_no_redirect(&self) -> Result<Client>
pub fn build_no_redirect(&self) -> Result<Client>
Builds a reqwest::Client from this configuration with redirects disabled.
Redirect suppression is applied after any customizer hook so security-sensitive flows such as OAuth token exchange cannot be redirected.