From b69d9a8428bafdd5e891670daf844c719c285ae8 Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Mon, 18 Mar 2024 09:28:13 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"fix:=20Remove=20content-encoding=20he?= =?UTF-8?q?ader=20from=20already=20decompressed=20respons=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 822a3c3af11e957c60a27abe4c5e9dd738678ebf. --- .changeset/dirty-moles-exercise.md | 5 ----- packages/fetch/src/fetch.js | 3 --- packages/fetch/test/main.js | 8 ++------ 3 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 .changeset/dirty-moles-exercise.md diff --git a/.changeset/dirty-moles-exercise.md b/.changeset/dirty-moles-exercise.md deleted file mode 100644 index dd3e50e..0000000 --- a/.changeset/dirty-moles-exercise.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@remix-run/web-fetch": patch ---- - -fix: Remove content-encoding header from already decompressed responses. This eases the use of fetch in senarios where you wish to use it as a sort of makeshift proxy. diff --git a/packages/fetch/src/fetch.js b/packages/fetch/src/fetch.js index 026318c..6a76542 100644 --- a/packages/fetch/src/fetch.js +++ b/packages/fetch/src/fetch.js @@ -277,7 +277,6 @@ async function fetch(url, options_ = {}) { // For gzip if (codings === 'gzip' || codings === 'x-gzip') { - responseOptions.headers.delete("Content-Encoding"); body = pump(body, zlib.createGunzip(zlibOptions), reject); response = new Response(fromAsyncIterable(body), responseOptions); resolve(response); @@ -286,7 +285,6 @@ async function fetch(url, options_ = {}) { // For deflate if (codings === 'deflate' || codings === 'x-deflate') { - responseOptions.headers.delete("Content-Encoding"); // Handle the infamous raw deflate response from old servers // a hack for old IIS and Apache servers const raw = pump(response_, new PassThrough(), reject); @@ -306,7 +304,6 @@ async function fetch(url, options_ = {}) { // For br if (codings === 'br') { - responseOptions.headers.delete("Content-Encoding"); body = pump(body, zlib.createBrotliDecompress(), reject); response = new Response(fromAsyncIterable(body), responseOptions); resolve(response); diff --git a/packages/fetch/test/main.js b/packages/fetch/test/main.js index df360a9..9388bce 100644 --- a/packages/fetch/test/main.js +++ b/packages/fetch/test/main.js @@ -818,7 +818,6 @@ describe("node-fetch", () => { const url = `${base}gzip`; return fetch(url).then((res) => { expect(res.headers.get("content-type")).to.equal("text/plain"); - expect(res.headers.get("content-encoding")).to.be.null; return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.equal("hello world"); @@ -837,9 +836,10 @@ describe("node-fetch", () => { }); }); - it("should decompress capitalised Content-Encoding", () => { + it("should make capitalised Content-Encoding lowercase", () => { const url = `${base}gzip-capital`; return fetch(url).then((res) => { + expect(res.headers.get("content-encoding")).to.equal("gzip"); return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.equal("hello world"); @@ -851,7 +851,6 @@ describe("node-fetch", () => { const url = `${base}deflate`; return fetch(url).then((res) => { expect(res.headers.get("content-type")).to.equal("text/plain"); - expect(res.headers.get("content-encoding")).to.be.null; return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.equal("hello world"); @@ -878,7 +877,6 @@ describe("node-fetch", () => { const url = `${base}brotli`; return fetch(url).then((res) => { expect(res.headers.get("content-type")).to.equal("text/plain"); - expect(res.headers.get("content-encoding")).to.be.null; return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.equal("hello world"); @@ -908,7 +906,6 @@ describe("node-fetch", () => { const url = `${base}sdch`; return fetch(url).then((res) => { expect(res.headers.get("content-type")).to.equal("text/plain"); - expect(res.headers.get("content-encoding")).to.equal("sdch"); return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.equal("fake sdch string"); @@ -960,7 +957,6 @@ describe("node-fetch", () => { }; return fetch(url, options).then((res) => { expect(res.headers.get("content-type")).to.equal("text/plain"); - expect(res.headers.get("content-encoding")).to.equal("gzip"); return res.text().then((result) => { expect(result).to.be.a("string"); expect(result).to.not.equal("hello world");