Skip to content

Commit

Permalink
Revert "fix: Remove content-encoding header from already decompressed…
Browse files Browse the repository at this point in the history
… respons…" (#61)

This reverts commit 822a3c3.
  • Loading branch information
jacob-ebey authored Mar 18, 2024
1 parent 822a3c3 commit 050356b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
5 changes: 0 additions & 5 deletions .changeset/dirty-moles-exercise.md

This file was deleted.

3 changes: 0 additions & 3 deletions packages/fetch/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions packages/fetch/test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 050356b

Please sign in to comment.