mirror of
https://github.com/fafhrd91/actix-web
synced 2025-02-23 12:33:02 +01:00
fix response body when no content-length header
This commit is contained in:
parent
17218dc6c8
commit
5f1a4607e5
@ -7,6 +7,10 @@
|
|||||||
- Add `body::to_body_limit()` function.
|
- Add `body::to_body_limit()` function.
|
||||||
- Add `body::BodyLimitExceeded` error type.
|
- Add `body::BodyLimitExceeded` error type.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix `MessageType::set_headers` not using the correct payload decoder when Transfer-Encoding and Content-Length are absent.
|
||||||
|
|
||||||
## 3.3.1 - 2023-03-02
|
## 3.3.1 - 2023-03-02
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
@ -395,8 +395,20 @@ impl MessageType for ResponseHead {
|
|||||||
// switching protocol or connect
|
// switching protocol or connect
|
||||||
PayloadType::Stream(PayloadDecoder::eof())
|
PayloadType::Stream(PayloadDecoder::eof())
|
||||||
} else {
|
} else {
|
||||||
// for HTTP/1.0 read to eof and close connection
|
let body_allowed = match msg.status.as_u16() {
|
||||||
if msg.version == Version::HTTP_10 {
|
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);
|
msg.set_connection_type(ConnectionType::Close);
|
||||||
PayloadType::Payload(PayloadDecoder::eof())
|
PayloadType::Payload(PayloadDecoder::eof())
|
||||||
} else {
|
} else {
|
||||||
|
@ -769,7 +769,7 @@ async fn client_unread_response() {
|
|||||||
|
|
||||||
// awc does not read all bytes unless content-length is specified
|
// awc does not read all bytes unless content-length is specified
|
||||||
let bytes = res.body().await.unwrap();
|
let bytes = res.body().await.unwrap();
|
||||||
assert_eq!(bytes, Bytes::from_static(b""));
|
assert_eq!(bytes, Bytes::from_static(b"welcome!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user