Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use super::Body;
use crate::async_impl::h3_client::connect::{H3ClientConfig, H3Connector};
#[cfg(feature = "http3")]
use crate::async_impl::h3_client::H3Client;
use crate::config::{RequestConfig, TotalTimeout};
use crate::config::{ReadTimeout, RequestConfig, TotalTimeout};
#[cfg(unix)]
use crate::connect::uds::UnixSocketProvider;
use crate::connect::{
Expand Down Expand Up @@ -999,7 +999,7 @@ impl ClientBuilder {
},
headers: config.headers,
referer: config.referer,
read_timeout: config.read_timeout,
read_timeout: RequestConfig::new(config.read_timeout),
total_timeout: RequestConfig::new(config.timeout),
hyper,
proxies,
Expand Down Expand Up @@ -2531,11 +2531,8 @@ impl Client {
.map(tokio::time::sleep)
.map(Box::pin);

let read_timeout_fut = self
.inner
.read_timeout
.map(tokio::time::sleep)
.map(Box::pin);
let read_timeout = self.inner.read_timeout.fetch(&extensions).copied();
let read_timeout_fut = read_timeout.map(tokio::time::sleep).map(Box::pin);

Pending {
inner: PendingInner::Request(Box::pin(PendingRequest {
Expand All @@ -2548,7 +2545,7 @@ impl Client {
in_flight,
total_timeout,
read_timeout_fut,
read_timeout: self.inner.read_timeout,
read_timeout,
})),
}
}
Expand Down Expand Up @@ -2795,7 +2792,7 @@ struct ClientRef {
h3_client: Option<LayeredService<H3Client>>,
referer: bool,
total_timeout: RequestConfig<TotalTimeout>,
read_timeout: Option<Duration>,
read_timeout: RequestConfig<ReadTimeout>,
proxies: Arc<Vec<ProxyMatcher>>,
proxies_maybe_http_auth: bool,
proxies_maybe_http_custom_headers: bool,
Expand Down Expand Up @@ -2831,11 +2828,8 @@ impl ClientRef {

f.field("default_headers", &self.headers);

self.read_timeout.fmt_as_field(f);
self.total_timeout.fmt_as_field(f);

if let Some(ref d) = self.read_timeout {
f.field("read_timeout", d);
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/async_impl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::client::{Client, Pending};
#[cfg(feature = "multipart")]
use super::multipart;
use super::response::Response;
use crate::config::{RequestConfig, TotalTimeout};
use crate::config::{ReadTimeout, RequestConfig, TotalTimeout};
#[cfg(feature = "multipart")]
use crate::header::CONTENT_LENGTH;
use crate::header::{HeaderMap, HeaderName, HeaderValue, CONTENT_TYPE};
Expand Down Expand Up @@ -124,6 +124,18 @@ impl Request {
RequestConfig::<TotalTimeout>::get_mut(&mut self.extensions)
}

/// Get the read timeout.
#[inline]
pub fn read_timeout(&self) -> Option<&Duration> {
RequestConfig::<ReadTimeout>::get(&self.extensions)
}

/// Get a mutable reference to the read timeout.
#[inline]
pub fn read_timeout_mut(&mut self) -> &mut Option<Duration> {
RequestConfig::<ReadTimeout>::get_mut(&mut self.extensions)
}

/// Get the http version.
#[inline]
pub fn version(&self) -> Version {
Expand Down
12 changes: 12 additions & 0 deletions src/blocking/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ impl Request {
self.inner.timeout_mut()
}

/// Get the read timeout.
#[inline]
pub fn read_timeout(&self) -> Option<&Duration> {
self.inner.read_timeout()
}

/// Get a mutable reference to the read timeout.
#[inline]
pub fn read_timeout_mut(&mut self) -> &mut Option<Duration> {
self.inner.read_timeout_mut()
}

/// Attempts to clone the `Request`.
///
/// None is returned if a body is which can not be cloned. This can be because the body is a
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ pub(crate) struct TotalTimeout;
impl RequestConfigValue for TotalTimeout {
type Value = Duration;
}

#[derive(Clone, Copy)]
pub(crate) struct ReadTimeout;

impl RequestConfigValue for ReadTimeout {
type Value = Duration;
}