question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for content-encoding: deflate raw

See original GitHub issue

How does one ask Express to process a POST with a header for ‘content-encoding: deflate’ where the data is raw (without the data headers and footers)?

I’m noticing there’s code in express node-fetch that checks for magic bytes in the first block to decide between createInflate() and createInflateRaw() but it’s not in body-parser.

body-parser read.js

switch (encoding) {
    case 'deflate':
      stream = zlib.createInflate()
      req.pipe(stream)
      break
    case 'gzip':
       ...

node-fetch index.js

const raw = res.pipe(new PassThrough$1());
raw.once('data', function (chunk) {
    // see http://stackoverflow.com/questions/37519828
    if ((chunk[0] & 0x0F) === 0x08) {
        body = body.pipe(zlib.createInflate());
    } else {
        body = body.pipe(zlib.createInflateRaw());
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Nov 27, 2021

It’s interesting that expressjs goes outside the standard to support deflate raw in node-fetch, but remains strict in body-parser.

I’m not sure what leads you to believe that the expressjs project manages node-fetch. We only manage the projets in our expresssjs github organization. I’m not even sure who manages node-fetch, but it is certainly unrelated to expressjs.

It’s also interesting to realize that after all this time, the standard is a bit off and could have been improved.

We don’t manage the standards, just implement them. If you think the standards should be changed, you should reach out to the standard organization that manages that particular one and have them update it.

1reaction
dougwilsoncommented, Nov 27, 2021

How does one ask Express to process a POST with a header for ‘content-encoding: deflate’ where the data is raw (without the data headers and footers)?

Sorry, I missed this direct question at the top 😅. There isn’t really a good way to do this with body-parser currently. You can always use the raw() parser and delete req.headers[‘content-encoding’] . But perhaps a better method would be someone who needs this feature can contribute an API to define custom decoders based on the content-encoding (and override existing ones with their custom impls).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content-Encoding - HTTP - MDN Web Docs
The Content-Encoding representation header lists any encodings that have been applied to the representation (message payload), ...
Read more >
Handling HTTP ContentEncoding "deflate" - Stack Overflow
After this I have suggested the archive manager I'm using to support decoding raw deflate data so I can just try to open...
Read more >
invalid header check when Content-Encoding: deflate and it's ...
Because this method detects based on the binary header. But I encountered deflate responses without headers, which only inflateRaw could ...
Read more >
Content Encoding - Everything curl
The deflate , gzip , zstd and br content encodings are supported by libcurl. ... is returned in its raw form and the...
Read more >
Dubious HTTP II - Unusual HTTP Content-Encodings
The Content-Encoding header is usually used to specify a compression of the content. The usual values are either gzip (RFC1952) and deflate ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found