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.

Can I force gzip decode?

See original GitHub issue

My request returns a gzip encoded response but the responding server does not set the content-encoding to gzip. Looking at the code, the automatic gzip decoding only activates if content-encoding is gzip or am I missing something. Is there a way to force enable the gzip decoding? Or am i stuck with having to decode the response with my own code?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
xxczakicommented, May 16, 2020

@teolag That’s right - when there is no `content-encoding header, node-fetch does not decode the response:

https://github.com/node-fetch/node-fetch/blob/0936a9af0a049eb05897779f3f0df6b903a95d60/src/index.js#L225

Right now there is no other way than handling the decompression yourself. I would highly recommend asking the server owner (if it’s possible of course) to add this header. We might add an option to force the decoding in the future.

0reactions
alexandregiordanellicommented, Mar 20, 2022
import fetch, { Response } from "node-fetch";
import { pipeline } from "stream";
import { createGunzip } from "zlib";

fetch(url)
.then((x) => new Response(pipeline(x.body, createGunzip(), () => {}))) // strange but it works, if remove the useless function it dies; ()=>{}
    .then((x) => x.text()) //or whatever your content is 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Force gzip to decompress despite CRC error - Stack Overflow
The gzip command will decompress all valid deflate data and write it out before checking the crc. So if, for example, I take...
Read more >
3 Invoking gzip - GNU.org
Decompress. Force compression or decompression even if the file has multiple links or the corresponding file already exists, or if the compressed data...
Read more >
Gzip decompress on file with other extension?
Normally unzipping restores the name and date of the original file (when it was compressed); this doesn't happen with -c . If you...
Read more >
How To Optimize Your Site With GZIP Compression
In your browser: In Chrome, open the Developer Tools > Network Tab (Firefox/IE will be similar). Refresh your page, and click the network...
Read more >
How to Enable GZIP Compression to Speed Up WordPress Sites
Learn how to enable GZIP compression to speed up your WordPress site on various web servers like Apache, Nginx, and IIS.
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