diff options
author | Satya Rohith <me@satyarohith.com> | 2022-03-07 22:43:15 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-07 22:43:15 +0530 |
commit | 670aef5c1a07c67f78a521eb13b05419b4c81f8a (patch) | |
tree | 2fb98e3c71368b9bae3231bfb93b3cce816963a9 /ext/http/lib.rs | |
parent | 4e1da28b391de0c9ef1911f79d913bf604c0c3ac (diff) |
fix(ext/http): drop content-length header on compression (#13866)
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r-- | ext/http/lib.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs index b70bed464..ae5ddb9c3 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -610,6 +610,10 @@ async fn op_http_write_headers( body_compressible && data.len() > 20 && accepts_compression; if should_compress { + // Drop 'content-length' header. Hyper will update it using compressed body. + if let Some(headers) = builder.headers_mut() { + headers.remove("content-length"); + } // If user provided a ETag header for uncompressed data, we need to // ensure it is a Weak Etag header ("W/"). if let Some(value) = etag_header { @@ -646,7 +650,7 @@ async fn op_http_write_headers( // https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_comp_level let mut writer = GzEncoder::new(Vec::new(), Compression::new(1)); writer.write_all(&data.into_bytes())?; - body = builder.body(writer.finish().unwrap().into())?; + body = builder.body(writer.finish()?.into())?; } } } else { |