From f3751d83f87d56d7d8b3e1ebea5f7931da7beec2 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 22 Jul 2019 11:35:00 +0600 Subject: [PATCH] Modify response body only if encoder is not None #997 --- actix-http/CHANGES.md | 6 ++++++ actix-http/src/encoding/encoder.rs | 32 ++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index cc695fa63..4b53161ae 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,5 +1,11 @@ # Changes +## [0.2.8] - 2019-07-xx + +### Fixed + +* Invalid response with compression middleware enabled, but compression-related features disabled #997 + ## [0.2.7] - 2019-07-18 ### Added diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index fa95d798a..58d8a2d9e 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -54,22 +54,24 @@ impl Encoder { }; if can_encode { - update_head(encoding, head); - head.no_chunking(false); - ResponseBody::Body(Encoder { - body, - eof: false, - fut: None, - encoder: ContentEncoder::encoder(encoding), - }) - } else { - ResponseBody::Body(Encoder { - body, - eof: false, - fut: None, - encoder: None, - }) + // Modify response body only if encoder is not None + if let Some(enc) = ContentEncoder::encoder(encoding) { + update_head(encoding, head); + head.no_chunking(false); + return ResponseBody::Body(Encoder { + body, + eof: false, + fut: None, + encoder: Some(enc), + }); + } } + ResponseBody::Body(Encoder { + body, + eof: false, + fut: None, + encoder: None, + }) } }