node-fetch icon indicating copy to clipboard operation
node-fetch copied to clipboard

RFC: Drop `compress` option?

Open tinovyatkin opened this issue 5 years ago • 6 comments

There is a standard way to disable compression support in fetch via Accept-Encoding header (works right now in node-fetch):

const res = await fetch("https://something.com/", {
  headers: { "Accept-Encoding": "identity" }
});

Do we really need a Node-only option here?

tinovyatkin avatar Jun 13 '20 01:06 tinovyatkin

bonus question: Is there a way to discard the hole 'accept-encoding' from even being sent in the first place?

noting === identity also

Guess that is what compress true/false is all about...


would be annoying if we removed the default accept-encoding and all of the sudden you would have to add it anywhere you want it.

jimmywarting avatar Jun 13 '20 19:06 jimmywarting

what if... they added "Accept-Encoding": "identity" but durning the request it gets removed only if it match Identity?

jimmywarting avatar Jun 13 '20 19:06 jimmywarting

We need this feature: https://github.com/node-fetch/node-fetch/issues/465#issuecomment-435816667

We want to request the content with gzip, defalte, br but do not automatically decompress in node-fetch. compress options is the only way to do this so in this case compress option should not be deprecated. (or rename to decompress like axios does)?

Fonger avatar Nov 03 '20 02:11 Fonger

identity means "request the content without compressing it" not "request the content as it's being sent without decompressing the receiving content"

So if you want the raw data as gzip then compress has a value. Think I wanted to use it myself at some point.

jimmywarting avatar Nov 03 '20 11:11 jimmywarting

I disagree that the compress option should be removed, but I do think it should be deprecated and renamed decompress since it controls decompressing the response rather than compressing the request.

Consider the scenario where the developer wants to implement their own decompression algorithm, maybe for coursework experimentation:

const res = await fetch("https://something.com/", {
  headers: {
    'Accept-Encoding': 'deflate'
  },
  compress: false
});

However, it does seem we should consider changing the behavior when setting compress: false to also set Accept-Encoding: identity. Consider this next example -- the response body may or may not be compressed since no Accept-Encoding header is sent; however, this is likely not what the developer intended:

const res = await fetch("https://something.com/", {
  compress: false
});

They probably intended this:

const res = await fetch("https://something.com/", {
  headers: {
    'Accept-Encoding': 'identity'
  },
  compress: false
});

tekwiz avatar Dec 20 '20 19:12 tekwiz

I can see a value in keeping this option... specially for those who wish to just proxy/forward a compressed response along. However. I think the name compress is slightly confusing. as the name applies that it should compress something while posting data.

it should be named something else...

  • it could be decompress: true.
  • or something closer to 'Accept-Encoding' and 'Content-Encoding' could be decode: true.

jimmywarting avatar Jan 22 '22 23:01 jimmywarting