[−][src]Struct isahc::HttpClientBuilder
An HTTP client builder, capable of creating custom HttpClient
instances
with customized behavior.
Examples
use isahc::config::RedirectPolicy; use isahc::http; use isahc::prelude::*; use std::time::Duration; let client = HttpClient::builder() .timeout(Duration::from_secs(60)) .redirect_policy(RedirectPolicy::Limit(10)) .preferred_http_version(http::Version::HTTP_2) .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 cookies(self) -> Self
[src]
Enable persistent cookie handling using a cookie jar.
This method requires the cookies
feature to be enabled.
pub fn middleware(self, middleware: impl Middleware) -> Self
[src]
Add a middleware layer to the client.
This method requires the middleware-api
feature to be enabled.
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 timeout(self, timeout: Duration) -> Self
[src]
Set a timeout for the maximum time allowed for a request-response cycle.
If not set, no timeout will be enforced.
pub fn connect_timeout(self, timeout: Duration) -> Self
[src]
Set a timeout for the initial connection phase.
If not set, a connect timeout of 300 seconds will be used.
pub fn redirect_policy(self, policy: RedirectPolicy) -> Self
[src]
Set a policy for automatically following server redirects.
The default is to not follow redirects.
pub fn auto_referer(self) -> Self
[src]
Update the Referer
header automatically when following redirects.
pub fn preferred_http_version(self, version: Version) -> Self
[src]
Set a preferred HTTP version the client should attempt to use to communicate to the server with.
This is treated as a suggestion. A different version may be used if the server does not support it or negotiates a different version.
pub fn tcp_keepalive(self, interval: Duration) -> Self
[src]
Enable TCP keepalive with a given probe interval.
pub fn tcp_nodelay(self) -> Self
[src]
Enables the TCP_NODELAY
option on connect.
pub fn proxy(self, proxy: Uri) -> Self
[src]
Set a proxy to use for requests.
The proxy protocol is specified by the URI scheme.
http
: Proxy. Default when no scheme is specified.https
: HTTPS Proxy. (Added in 7.52.0 for OpenSSL, GnuTLS and NSS)socks4
: SOCKS4 Proxy.socks4a
: SOCKS4a Proxy. Proxy resolves URL hostname.socks5
: SOCKS5 Proxy.socks5h
: SOCKS5 Proxy. Proxy resolves URL hostname.
By default no proxy will be used, unless one is specified in either the
http_proxy
or https_proxy
environment variables.
pub fn max_upload_speed(self, max: u64) -> Self
[src]
Set a maximum upload speed for the request body, in bytes per second.
The default is unlimited.
pub fn max_download_speed(self, max: u64) -> Self
[src]
Set a maximum download speed for the response body, in bytes per second.
The default is unlimited.
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_servers(self, servers: impl IntoIterator<Item = SocketAddr>) -> Self
[src]
Set a list of specific DNS servers to be used for DNS resolution.
By default this option is not set and the system's built-in DNS resolver is used. This option can only be used if libcurl is compiled with c-ares, otherwise this option has no effect.
pub fn ssl_ciphers(self, servers: impl IntoIterator<Item = String>) -> Self
[src]
Set a list of ciphers to use for SSL/TLS connections.
The list of valid cipher names is dependent on the underlying SSL/TLS engine in use. You can find an up-to-date list of potential cipher names at https://curl.haxx.se/docs/ssl-ciphers.html.
The default is unset and will result in the system defaults being used.
pub fn ssl_client_certificate(self, certificate: ClientCertificate) -> Self
[src]
Set a custom SSL/TLS client certificate to use for all client connections.
If a format is not supported by the underlying SSL/TLS engine, an error will be returned when attempting to send a request using the offending certificate.
The default value is none.
Examples
let client = HttpClient::builder() .ssl_client_certificate(ClientCertificate::PEM { path: "client.pem".into(), private_key: Some(PrivateKey::PEM { path: "key.pem".into(), password: Some("secret".into()), }), }) .build()?;
pub fn danger_allow_unsafe_ssl(self, allow_unsafe: bool) -> Self
[src]
Controls the use of certificate validation.
Defaults to false
as per libcurl's default.
Warning
You should think very carefully before using this method. If invalid certificates are trusted, any certificate for any site will be trusted for use. This includes expired certificates. This introduces significant vulnerabilities, and should only be used as a last resort.
pub fn metrics(self, enable: bool) -> Self
[src]
Enable comprehensive per-request metrics collection.
When enabled, detailed timing metrics will be tracked while a request is
in progress, such as bytes sent and received, estimated size, DNS lookup
time, etc. For a complete list of the available metrics that can be
inspected, see the Metrics
documentation.
When enabled, to access a view of the current metrics values you can use
ResponseExt::metrics
.
While effort is taken to optimize hot code in metrics collection, it is likely that enabling it will have a small effect on overall throughput. Disabling metrics may be necessary for absolute peak performance.
By default metrics are disabled.
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 Default for HttpClientBuilder
[src]
fn default() -> HttpClientBuilder
[src]
impl Debug for HttpClientBuilder
[src]
Auto Trait Implementations
impl Send for HttpClientBuilder
impl Sync for HttpClientBuilder
impl Unpin for HttpClientBuilder
impl !UnwindSafe for HttpClientBuilder
impl !RefUnwindSafe for HttpClientBuilder
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,