pub struct Client { /* private fields */ }Expand description
A pooled HTTP client.
Cloning is cheap and shares the connection pool, so build one per process and clone it into whatever needs it. Building one per request would open a fresh connection every time, which is the single most common way to make an outbound call slow.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
A client with pooled connections, a 30 second timeout, a 16 MiB response ceiling, and redirect following up to 10 hops.
Sourcepub fn timeout(self, d: Duration) -> Self
pub fn timeout(self, d: Duration) -> Self
Fail a request that has not finished after d.
The deadline covers the whole request including redirects, not each hop, so a redirect chain cannot multiply the time a caller waits.
Sourcepub fn max_response_bytes(self, bytes: usize) -> Self
pub fn max_response_bytes(self, bytes: usize) -> Self
Refuse a response body larger than bytes.
The ceiling applies to the payload the caller sees: after transparent decompression when that is enabled, so a compressed response cannot expand past this limit either.
Sourcepub fn max_redirects(self, n: usize) -> Self
pub fn max_redirects(self, n: usize) -> Self
Follow at most n redirects. Zero returns the redirect response itself.
Sourcepub fn auto_decompress(self, enabled: bool) -> Self
pub fn auto_decompress(self, enabled: bool) -> Self
Advertise and decode gzip / deflate response bodies.
Enabled by default. Set to false to leave Content-Encoding bodies
untouched and stop sending Accept-Encoding.
Sourcepub fn user_agent(self, value: &str) -> Result<Self, ClientError>
pub fn user_agent(self, value: &str) -> Result<Self, ClientError>
Sourcepub fn default_header(
self,
name: &str,
value: &str,
) -> Result<Self, ClientError>
pub fn default_header( self, name: &str, value: &str, ) -> Result<Self, ClientError>
Sourcepub fn request(&self, method: Method, url: impl Into<String>) -> RequestBuilder
pub fn request(&self, method: Method, url: impl Into<String>) -> RequestBuilder
Start a request with an arbitrary method.
Sourcepub fn get(&self, url: impl Into<String>) -> RequestBuilder
pub fn get(&self, url: impl Into<String>) -> RequestBuilder
Start a GET.
Sourcepub fn post(&self, url: impl Into<String>) -> RequestBuilder
pub fn post(&self, url: impl Into<String>) -> RequestBuilder
Start a POST.
Sourcepub fn put(&self, url: impl Into<String>) -> RequestBuilder
pub fn put(&self, url: impl Into<String>) -> RequestBuilder
Start a PUT.
Sourcepub fn patch(&self, url: impl Into<String>) -> RequestBuilder
pub fn patch(&self, url: impl Into<String>) -> RequestBuilder
Start a PATCH.
Sourcepub fn delete(&self, url: impl Into<String>) -> RequestBuilder
pub fn delete(&self, url: impl Into<String>) -> RequestBuilder
Start a DELETE.
Sourcepub fn head(&self, url: impl Into<String>) -> RequestBuilder
pub fn head(&self, url: impl Into<String>) -> RequestBuilder
Start a HEAD.