Skip to content

Commit

Permalink
fix: response body timeout forwards the size hint
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmonstar committed Mar 29, 2024
1 parent 872af0c commit 13e27b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ where
.map(|opt_chunk| opt_chunk.map_err(crate::error::body)),
)
}

#[inline]
fn size_hint(&self) -> http_body::SizeHint {
self.inner.size_hint()
}

#[inline]
fn is_end_stream(&self) -> bool {
self.inner.is_end_stream()
}
}

pub(crate) type ResponseBody =
Expand Down
20 changes: 20 additions & 0 deletions tests/timeouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,23 @@ fn write_timeout_large_body() {
assert!(err.is_timeout());
assert_eq!(err.url().map(|u| u.as_str()), Some(url.as_str()));
}

#[tokio::test]
async fn response_body_timeout_forwards_size_hint() {
let _ = env_logger::try_init();

let server = server::http(move |_req| async { http::Response::new(b"hello".to_vec().into()) });

let client = reqwest::Client::new();

let url = format!("http://{}/slow", server.addr());

let res = client
.get(&url)
.timeout(Duration::from_secs(1))
.send()
.await
.expect("response");

assert_eq!(res.content_length(), Some(5));
}

0 comments on commit 13e27b7

Please sign in to comment.