diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 7324cba5a..383f8e4f5 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -28,6 +28,10 @@ - Add `error::InvalidStatusCode` re-export. +### Fixed + +- Fix `MessageType::set_headers` not using the correct payload decoder when Transfer-Encoding and Content-Length are absent. + ## 3.7.0 ### Added diff --git a/actix-http/src/h1/decoder.rs b/actix-http/src/h1/decoder.rs index af64e8802..37ff83d01 100644 --- a/actix-http/src/h1/decoder.rs +++ b/actix-http/src/h1/decoder.rs @@ -391,8 +391,20 @@ impl MessageType for ResponseHead { // switching protocol or connect PayloadType::Stream(PayloadDecoder::eof()) } else { - // for HTTP/1.0 read to eof and close connection - if msg.version == Version::HTTP_10 { + let body_allowed = match msg.status.as_u16() { + 100..=199 => false, + 204 => false, + 304 => false, + _ => true, + }; + // for HTTP/1.0 and HTTP/1.1 read to eof and close connection + if msg.version == Version::HTTP_11 && body_allowed { + if let Some(ConnectionType::Close) = msg.conn_type() { + PayloadType::Payload(PayloadDecoder::eof()) + } else { + PayloadType::None + } + } else if msg.version == Version::HTTP_10 { msg.set_connection_type(ConnectionType::Close); PayloadType::Payload(PayloadDecoder::eof()) } else { diff --git a/awc/tests/test_client.rs b/awc/tests/test_client.rs index 43c83891a..6fd56823f 100644 --- a/awc/tests/test_client.rs +++ b/awc/tests/test_client.rs @@ -749,7 +749,7 @@ async fn client_unread_response() { // awc does not read all bytes unless content-length is specified let bytes = res.body().await.unwrap(); - assert_eq!(bytes, Bytes::from_static(b"")); + assert_eq!(bytes, Bytes::from_static(b"welcome!")); } #[actix_rt::test]