Skip to content

Commit 13e27b7

Browse files
committed
fix: response body timeout forwards the size hint
1 parent 872af0c commit 13e27b7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/async_impl/body.rs

+10
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,16 @@ where
309309
.map(|opt_chunk| opt_chunk.map_err(crate::error::body)),
310310
)
311311
}
312+
313+
#[inline]
314+
fn size_hint(&self) -> http_body::SizeHint {
315+
self.inner.size_hint()
316+
}
317+
318+
#[inline]
319+
fn is_end_stream(&self) -> bool {
320+
self.inner.is_end_stream()
321+
}
312322
}
313323

314324
pub(crate) type ResponseBody =

tests/timeouts.rs

+20
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,23 @@ fn write_timeout_large_body() {
303303
assert!(err.is_timeout());
304304
assert_eq!(err.url().map(|u| u.as_str()), Some(url.as_str()));
305305
}
306+
307+
#[tokio::test]
308+
async fn response_body_timeout_forwards_size_hint() {
309+
let _ = env_logger::try_init();
310+
311+
let server = server::http(move |_req| async { http::Response::new(b"hello".to_vec().into()) });
312+
313+
let client = reqwest::Client::new();
314+
315+
let url = format!("http://{}/slow", server.addr());
316+
317+
let res = client
318+
.get(&url)
319+
.timeout(Duration::from_secs(1))
320+
.send()
321+
.await
322+
.expect("response");
323+
324+
assert_eq!(res.content_length(), Some(5));
325+
}

0 commit comments

Comments
 (0)