From 670aef5c1a07c67f78a521eb13b05419b4c81f8a Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Mon, 7 Mar 2022 22:43:15 +0530 Subject: fix(ext/http): drop content-length header on compression (#13866) --- ext/http/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ext/http/lib.rs') 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 { -- cgit v1.2.3