From ab09a42f5cf5dc1fa3daa5b90ac355f6a00bbd9a Mon Sep 17 00:00:00 2001 From: Shun Zi <20991618+shunf4@users.noreply.github.com> Date: Fri, 28 Jun 2024 21:42:32 +0800 Subject: [PATCH] fix: use accept-encoding instead of content-encoding for requests favoring gzip Per https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding , a request accepting gzip response ususally uses `Accept-Encoding` header, not `Content-Encoding` (which is used by the response). The original code is likely a typo. --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 898c8125..cf563add 100644 --- a/lib/index.js +++ b/lib/index.js @@ -70,7 +70,7 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) { } if (opts.gzip) { - headers['content-encoding'] = 'gzip' + headers['accept-encoding'] = 'gzip' if (bodyIsStream) { const gz = new zlib.Gzip() body.on('error', /* istanbul ignore next: unlikely and hard to test */