Skip to content

Commit

Permalink
Fix for incorrect Content-Length: 0 handling
Browse files Browse the repository at this point in the history
If the Content-Length header is set to 0, the client must not read the content from the stream, otherwise it hangs waiting for data. 
Redirect responses (302, 307) usally have no content and have Content-Length: 0
  • Loading branch information
ghu authored Apr 22, 2024
1 parent 7f50f7f commit 8000c69
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ impl<'a> RequestBuilder<'a> {
let deadline = Instant::now() + timeout;
copy_with_timeout(stream, writer, deadline)?;
} else {
let num_bytes = res.content_len().unwrap_or(0);

if num_bytes > 0 {
copy_exact(stream, writer, num_bytes - body_part.len())?;
if let Some(num_bytes) = res.content_len() {
if num_bytes > 0 {
copy_exact(stream, writer, num_bytes - body_part.len())?;
}
} else {
io::copy(stream, writer)?;
}
Expand Down

0 comments on commit 8000c69

Please sign in to comment.