Provide request timeout for blocking API (#764)
This commit is contained in:
committed by
Sean McArthur
parent
b159963f6c
commit
22fe6566ff
@@ -1,5 +1,6 @@
|
||||
use std::fmt;
|
||||
use std::convert::TryFrom;
|
||||
use std::time::Duration;
|
||||
|
||||
use base64::encode;
|
||||
use serde::Serialize;
|
||||
@@ -84,6 +85,18 @@ impl Request {
|
||||
&mut self.body
|
||||
}
|
||||
|
||||
/// Get the timeout.
|
||||
#[inline]
|
||||
pub fn timeout(&self) -> Option<&Duration> {
|
||||
self.inner.timeout()
|
||||
}
|
||||
|
||||
/// Get a mutable reference to the timeout.
|
||||
#[inline]
|
||||
pub fn timeout_mut(&mut self) -> &mut Option<Duration> {
|
||||
self.inner.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
|
||||
@@ -300,6 +313,18 @@ impl RequestBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Enables a request timeout.
|
||||
///
|
||||
/// The timeout is applied from the when the request starts connecting
|
||||
/// until the response body has finished. It affects only this request
|
||||
/// and overrides the timeout configured using `ClientBuilder::timeout()`.
|
||||
pub fn timeout(mut self, timeout: Duration) -> RequestBuilder {
|
||||
if let Ok(ref mut req) = self.request {
|
||||
*req.timeout_mut() = Some(timeout);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Modify the query string of the URL.
|
||||
///
|
||||
/// Modifies the URL of this request, adding the parameters provided.
|
||||
|
||||
Reference in New Issue
Block a user