From 12e00b8018ddfb078800ebc548879723665b4bce Mon Sep 17 00:00:00 2001 From: Nikita Galkin Date: Sat, 15 Feb 2020 12:10:58 +0200 Subject: [PATCH] Fixing issue for HEAD method and gziped repsonse (#2666) --- lib/adapters/http.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8b968e0..a483201 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -181,22 +181,22 @@ module.exports = function httpAdapter(config) { // uncompress the response body transparently if required var stream = res; + // return the last request in case of redirects + var lastRequest = res.req || req; + switch (res.headers['content-encoding']) { /*eslint default-case:0*/ case 'gzip': case 'compress': case 'deflate': // add the unzipper to the body stream processing pipeline - stream = (res.statusCode === 204) ? stream : stream.pipe(zlib.createUnzip()); + stream = (res.statusCode === 204 || lastRequest.method === 'HEAD') ? stream : stream.pipe(zlib.createUnzip()); // remove the content-encoding in order to not confuse downstream operations delete res.headers['content-encoding']; break; } - // return the last request in case of redirects - var lastRequest = res.req || req; - var response = { status: res.statusCode, statusText: res.statusMessage,