pub struct HttpClient { /* private fields */ }Expand description
HTTP client, see the module documentation. Cloning shares the connection pool.
Implementations§
Source§impl HttpClient
impl HttpClient
pub fn new() -> Self
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Longest a single attempt (connect, send, read the whole response) may take (default 30 s)
Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Longest name resolution + TCP/TLS connect may take (default 10 s)
Sourcepub fn max_response_bytes(self, max: usize) -> Self
pub fn max_response_bytes(self, max: usize) -> Self
Largest response body accepted (default 10 MiB)
Sourcepub fn max_redirects(self, max: usize) -> Self
pub fn max_redirects(self, max: usize) -> Self
Redirects followed per call (default 5, 0 returns the 3xx response itself)
Sourcepub fn retries(self, retries: u32) -> Self
pub fn retries(self, retries: u32) -> Self
Extra attempts after a failure that is safe to repeat (default 0)
Sourcepub fn retry_backoff(self, base: Duration) -> Self
pub fn retry_backoff(self, base: Duration) -> Self
First retry delay, doubled each time with jitter (default 200 ms)
Sourcepub fn public_only(self) -> Self
pub fn public_only(self) -> Self
Only connect to public addresses: loopback, private, link-local and
cloud-metadata targets are refused with ClientError::Blocked. Use it
whenever the URL comes from a user (webhooks, link previews, imports).
pub fn user_agent(self, agent: &str) -> Self
Sourcepub fn default_header(self, name: &str, value: &str) -> Self
pub fn default_header(self, name: &str, value: &str) -> Self
Header sent with every request (unless the request sets it itself)
Sourcepub fn pool_idle_timeout(self, timeout: Duration) -> Self
pub fn pool_idle_timeout(self, timeout: Duration) -> Self
Keep idle connections this long for reuse (default 30 s, zero disables pooling)
Sourcepub fn add_root_certificates_pem(self, pem: &[u8]) -> Result<Self, ClientError>
pub fn add_root_certificates_pem(self, pem: &[u8]) -> Result<Self, ClientError>
Trust these PEM root certificates in addition to the built-in ones, e.g.
a private CA (feature client-tls)