From 8000c69a216a9ff198e8396c7aa49160553befae Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 22 Apr 2024 22:18:57 +0300 Subject: [PATCH] Fix for incorrect Content-Length: 0 handling 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 --- src/request.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/request.rs b/src/request.rs index 02f7cfe..25eed96 100644 --- a/src/request.rs +++ b/src/request.rs @@ -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)?; }