Add connect_timeout to async and sync clients
This commit is contained in:
@@ -66,6 +66,9 @@ struct Config {
|
||||
hostname_verification: bool,
|
||||
#[cfg(feature = "tls")]
|
||||
certs_verification: bool,
|
||||
connect_timeout: Option<Duration>,
|
||||
#[cfg(feature = "tls")]
|
||||
identity: Option<Identity>,
|
||||
proxies: Vec<Proxy>,
|
||||
redirect_policy: RedirectPolicy,
|
||||
referer: bool,
|
||||
@@ -73,8 +76,6 @@ struct Config {
|
||||
#[cfg(feature = "tls")]
|
||||
root_certs: Vec<Certificate>,
|
||||
#[cfg(feature = "tls")]
|
||||
identity: Option<Identity>,
|
||||
#[cfg(feature = "tls")]
|
||||
tls: TlsBackend,
|
||||
http2_only: bool,
|
||||
local_address: Option<IpAddr>,
|
||||
@@ -97,6 +98,7 @@ impl ClientBuilder {
|
||||
hostname_verification: true,
|
||||
#[cfg(feature = "tls")]
|
||||
certs_verification: true,
|
||||
connect_timeout: None,
|
||||
proxies: Vec::new(),
|
||||
redirect_policy: RedirectPolicy::default(),
|
||||
referer: true,
|
||||
@@ -123,7 +125,7 @@ impl ClientBuilder {
|
||||
let config = self.config;
|
||||
let proxies = Arc::new(config.proxies);
|
||||
|
||||
let connector = {
|
||||
let mut connector = {
|
||||
#[cfg(feature = "tls")]
|
||||
match config.tls {
|
||||
#[cfg(feature = "default-tls")]
|
||||
@@ -177,6 +179,8 @@ impl ClientBuilder {
|
||||
Connector::new(proxies.clone(), config.local_address)?
|
||||
};
|
||||
|
||||
connector.set_timeout(config.connect_timeout);
|
||||
|
||||
let mut builder = ::hyper::Client::builder();
|
||||
if config.http2_only {
|
||||
builder.http2_only(true);
|
||||
@@ -312,7 +316,8 @@ impl ClientBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a timeout for both the read and write operations of a client.
|
||||
// Currently not used, so hide from docs.
|
||||
#[doc(hidden)]
|
||||
pub fn timeout(mut self, timeout: Duration) -> ClientBuilder {
|
||||
self.config.timeout = Some(timeout);
|
||||
self
|
||||
@@ -324,6 +329,19 @@ impl ClientBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set a timeout for only the connect phase of a `Client`.
|
||||
///
|
||||
/// Default is `None`.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This **requires** the futures be executed in a tokio runtime with
|
||||
/// a tokio timer enabled.
|
||||
pub fn connect_timeout(mut self, timeout: Duration) -> ClientBuilder {
|
||||
self.config.connect_timeout = Some(timeout);
|
||||
self
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[deprecated(note = "DNS no longer uses blocking threads")]
|
||||
pub fn dns_threads(self, _threads: usize) -> ClientBuilder {
|
||||
|
||||
Reference in New Issue
Block a user