From c6ec5fc867391eba5b8039e9c60b8968af7fa15d Mon Sep 17 00:00:00 2001 From: Jamie Telin Date: Thu, 12 May 2022 07:27:39 +0200 Subject: [PATCH] Fixing Z_BUF_ERROR when no content (#4701) * Fix Z_BUF_ERROR when no content * Refactored code * Fix undefined check Co-authored-by: Jay --- lib/adapters/http.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index bdf6d37..66aa3f2 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -236,9 +236,14 @@ module.exports = function httpAdapter(config) { // return the last request in case of redirects var lastRequest = res.req || req; + // if decompress disabled we should not decompress + if (config.decompress !== false) { + // if no content, but headers still say that it is encoded, + // remove the header not confuse downstream operations + if (data && data.length === 0 && res.headers['content-encoding']) { + delete res.headers['content-encoding']; + } - // if no content, is HEAD request or decompress disabled we should not decompress - if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) { switch (res.headers['content-encoding']) { /*eslint default-case:0*/ case 'gzip':