fix blocking client to use request timeout for response body (#1395)
This commit is contained in:
@@ -1039,7 +1039,7 @@ impl ClientHandle {
|
|||||||
Ok(Err(err)) => Err(err.with_url(url)),
|
Ok(Err(err)) => Err(err.with_url(url)),
|
||||||
Ok(Ok(res)) => Ok(Response::new(
|
Ok(Ok(res)) => Ok(Response::new(
|
||||||
res,
|
res,
|
||||||
self.timeout.0,
|
timeout,
|
||||||
KeepCoreThreadAlive(Some(self.inner.clone())),
|
KeepCoreThreadAlive(Some(self.inner.clone())),
|
||||||
)),
|
)),
|
||||||
Err(wait::Waited::TimedOut(e)) => Err(crate::error::request(e).with_url(url)),
|
Err(wait::Waited::TimedOut(e)) => Err(crate::error::request(e).with_url(url)),
|
||||||
|
|||||||
@@ -174,6 +174,43 @@ fn timeout_blocking_request() {
|
|||||||
assert_eq!(err.url().map(|u| u.as_str()), Some(url.as_str()));
|
assert_eq!(err.url().map(|u| u.as_str()), Some(url.as_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "blocking")]
|
||||||
|
#[test]
|
||||||
|
fn blocking_request_timeout_body() {
|
||||||
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
// this should be overridden
|
||||||
|
.connect_timeout(Duration::from_millis(200))
|
||||||
|
// this should be overridden
|
||||||
|
.timeout(Duration::from_millis(200))
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let server = server::http(move |_req| {
|
||||||
|
async {
|
||||||
|
// immediate response, but delayed body
|
||||||
|
let body = hyper::Body::wrap_stream(futures_util::stream::once(async {
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
Ok::<_, std::convert::Infallible>("Hello")
|
||||||
|
}));
|
||||||
|
|
||||||
|
http::Response::new(body)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let url = format!("http://{}/closes", server.addr());
|
||||||
|
let res = client
|
||||||
|
.get(&url)
|
||||||
|
// longer than client timeout
|
||||||
|
.timeout(Duration::from_secs(5))
|
||||||
|
.send()
|
||||||
|
.expect("get response");
|
||||||
|
|
||||||
|
let text = res.text().unwrap();
|
||||||
|
assert_eq!(text, "Hello");
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "blocking")]
|
#[cfg(feature = "blocking")]
|
||||||
#[test]
|
#[test]
|
||||||
fn write_timeout_large_body() {
|
fn write_timeout_large_body() {
|
||||||
|
|||||||
Reference in New Issue
Block a user