1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-25 11:01:14 +00:00

prevent hang when compressing Sized(0) bodies

fixes #3229
This commit is contained in:
Rob Ede 2023-12-25 02:27:51 +00:00
parent f4851b3914
commit d14e98b62b
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
2 changed files with 18 additions and 3 deletions

View file

@ -2,6 +2,10 @@
## Unreleased
## Fixed
- Prevent hang when returning zero-sized response bodies through compression layer.
## 3.5.0
### Changed

View file

@ -50,10 +50,21 @@ impl<B: MessageBody> Encoder<B> {
}
}
fn empty() -> Self {
Encoder {
body: EncoderBody::Full { body: Bytes::new() },
encoder: None,
fut: None,
eof: true,
}
}
pub fn response(encoding: ContentEncoding, head: &mut ResponseHead, body: B) -> Self {
// no need to compress an empty body
if matches!(body.size(), BodySize::None | BodySize::Sized(0)) {
return Self::none();
// no need to compress empty bodies
match body.size() {
BodySize::None => return Self::none(),
BodySize::Sized(0) => return Self::empty(),
_ => {}
}
let should_encode = !(head.headers().contains_key(&CONTENT_ENCODING)