[−][src]Struct isahc::HttpClientBuilder
An HTTP client builder, capable of creating custom HttpClient
instances
with customized behavior.
Any option that can be configured per-request can also be configured on a
client builder as a default setting. Request configuration is provided by
the Configurable
trait, which is also available in the
prelude
module.
Examples
use isahc::config::{RedirectPolicy, VersionNegotiation}; use isahc::prelude::*; use std::time::Duration; let client = HttpClient::builder() .timeout(Duration::from_secs(60)) .redirect_policy(RedirectPolicy::Limit(10)) .version_negotiation(VersionNegotiation::http2()) .build()?;
Methods
impl HttpClientBuilder
[src]
pub fn new() -> Self
[src]
Create a new builder for building a custom client. All configuration will start out with the default values.
This is equivalent to the Default
implementation.
pub fn max_connections(self, max: usize) -> Self
[src]
Set a maximum number of simultaneous connections that this client is allowed to keep open at one time.
If set to a value greater than zero, no more than max
connections will
be opened at one time. If executing a new request would require opening
a new connection, then the request will stay in a "pending" state until
an existing connection can be used or an active request completes and
can be closed, making room for a new connection.
Setting this value to 0
disables the limit entirely.
This is an effective way of limiting the number of sockets or file descriptors that this client will open, though note that the client may use file descriptors for purposes other than just HTTP connections.
By default this value is 0
and no limit is enforced.
To apply a limit per-host, see
HttpClientBuilder::max_connections_per_host
.
pub fn max_connections_per_host(self, max: usize) -> Self
[src]
Set a maximum number of simultaneous connections that this client is allowed to keep open to individual hosts at one time.
If set to a value greater than zero, no more than max
connections will
be opened to a single host at one time. If executing a new request would
require opening a new connection, then the request will stay in a
"pending" state until an existing connection can be used or an active
request completes and can be closed, making room for a new connection.
Setting this value to 0
disables the limit entirely. By default this
value is 0
and no limit is enforced.
To set a global limit across all hosts, see
HttpClientBuilder::max_connections
.
pub fn connection_cache_size(self, size: usize) -> Self
[src]
Set the size of the connection cache.
After requests are completed, if the underlying connection is reusable, it is added to the connection cache to be reused to reduce latency for future requests.
Setting the size to 0
disables connection caching for all requests
using this client.
By default this value is unspecified. A reasonable default size will be chosen.
pub fn dns_cache(self, cache: impl Into<DnsCache>) -> Self
[src]
Configure DNS caching.
By default, DNS entries are cached by the client executing the request and are used until the entry expires. Calling this method allows you to change the entry timeout duration or disable caching completely.
Note that DNS entry TTLs are not respected, regardless of this setting.
By default caching is enabled with a 60 second timeout.
Examples
let client = HttpClient::builder() // Cache entries for 10 seconds. .dns_cache(Duration::from_secs(10)) // Cache entries forever. .dns_cache(DnsCache::Forever) // Don't cache anything. .dns_cache(DnsCache::Disable) .build()?;
pub fn dns_resolve(self, map: ResolveMap) -> Self
[src]
Set a mapping of DNS resolve overrides.
Entries in the given map will be used first before using the default DNS resolver for host+port pairs.
Note that DNS resolving is only performed when establishing a new
Examples
let client = HttpClient::builder() .dns_resolve(ResolveMap::new() // Send requests for example.org on port 80 to 127.0.0.1. .add("example.org", 80, [127, 0, 0, 1])) .build()?;
pub fn build(self) -> Result<HttpClient, Error>
[src]
Build an HttpClient
using the configured options.
If the client fails to initialize, an error will be returned.
Trait Implementations
impl Configurable for HttpClientBuilder
[src]
fn timeout(self, timeout: Duration) -> Self
[src]
fn connect_timeout(self, timeout: Duration) -> Self
[src]
fn version_negotiation(self, negotiation: VersionNegotiation) -> Self
[src]
fn redirect_policy(self, policy: RedirectPolicy) -> Self
[src]
fn auto_referer(self) -> Self
[src]
fn authentication(self, authentication: Authentication) -> Self
[src]
fn credentials(self, credentials: Credentials) -> Self
[src]
fn tcp_keepalive(self, interval: Duration) -> Self
[src]
fn tcp_nodelay(self) -> Self
[src]
fn interface(self, interface: impl Into<NetworkInterface>) -> Self
[src]
fn proxy(self, proxy: impl Into<Option<Uri>>) -> Self
[src]
fn proxy_blacklist<I, T>(self, hosts: I) -> Self where
I: IntoIterator<Item = T>,
T: Into<String>,
[src]
I: IntoIterator<Item = T>,
T: Into<String>,
fn proxy_authentication(self, authentication: Authentication) -> Self
[src]
fn proxy_credentials(self, credentials: Credentials) -> Self
[src]
fn max_upload_speed(self, max: u64) -> Self
[src]
fn max_download_speed(self, max: u64) -> Self
[src]
fn dns_servers<I, T>(self, servers: I) -> Self where
I: IntoIterator<Item = T>,
T: Into<SocketAddr>,
[src]
I: IntoIterator<Item = T>,
T: Into<SocketAddr>,
fn ssl_client_certificate(self, certificate: ClientCertificate) -> Self
[src]
fn ssl_ca_certificate(self, certificate: CaCertificate) -> Self
[src]
fn ssl_ciphers<I, T>(self, servers: I) -> Self where
I: IntoIterator<Item = T>,
T: Into<String>,
[src]
I: IntoIterator<Item = T>,
T: Into<String>,
fn ssl_options(self, options: SslOption) -> Self
[src]
fn metrics(self, enable: bool) -> Self
[src]
impl Debug for HttpClientBuilder
[src]
impl Default for HttpClientBuilder
[src]
Auto Trait Implementations
impl !RefUnwindSafe for HttpClientBuilder
impl Send for HttpClientBuilder
impl Sync for HttpClientBuilder
impl Unpin for HttpClientBuilder
impl !UnwindSafe for HttpClientBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,