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.

Response is not getting compressed or being corrupted?

See original GitHub issue

this is my middleware code

app.use(compress({ filter: function (content_type) { return /text/i.test(content_type) }, threshold: 1, flush: require('zlib').Z_SYNC_FLUSH }))

And this is my response code

ctx.body = 'Hello world'
ctx.compress = true
ctx.set('Content-Type', 'text/plain')
ctx.set('content-encoding', 'gzip')

now when I hit the url localhost:3000/test, I get the error saying

ERR_CONTENT_DECODING_FAILED

But when I hit same url using CURL, I get the text saying

Hello World

I guess it’s apparent that data is not getting compressed otherwise curl wouldn’t have shown plain text. And I think Chrome error is due to content-encoding being gzip but actual data being plain text. May be I’m wrong but this is sure that there is some problem is my code otherwise chrome should have shown Hello World without error, isn’t?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ashishnetworkscommented, Jun 21, 2017

Thank you @jonathanong for your comments. I just retested the whole process once again and I realised that my code was already working. I was making mistakes in assuming that response should always be compressed. But what I realised now, after lots of research is that compression works only when the client sends a header with Accept-Encoding. If supported Accept-Encoding is gzip, the response will be compressed in gzip if it’s deflate, the response shall be compressed in deflate form, and if it’s not mentioned response shall be simple plain data. I was receiving plain text in curl because curl does not send Accept-Encoding in its default request, but when I sent curl request using curl -H 'Accept-Encoding: gzip' -D - http://localhost:3000 my response was coded into compressed form. So my code has been working for always. Thanks

Edit: And you were also right that if content-encoding is set, module will not run so we don’t have to explicitly set the content-encoding, it should be set by compression middleware depending on Accept-Encoding of the request

0reactions
jonathanongcommented, Jun 21, 2017

pull request

Read more comments on GitHub >

github_iconTop Results From Across the Web

Corrupted Response due to HTTP compression | Progress ...
Corrupted Response due to HTTP compression. When you are importing or recording traffic, sometimes the request may contain an Accept-Encoding header that ...
Read more >
AJAX response gives a corrupted compressed (.tgz) file
(b) The file has been partially decompressed because when I inspect the request Header I can state "Accept-Encoding: gzip, deflate"; although I don't...
Read more >
The WOF Driver encountered a corruption in the compressed ...
The WOF driver encountered corruption in the compressed file's Resource Table. The DISM log file can be found at C:\WINDOWS\ ...
Read more >
File corruption during ftp transfer ASCII vs. BINARY
Sorry for the problem with the file being corrupted. The file itself is what needs to be compressed. My suggestion is that you...
Read more >
WP Optimise Corrupt Images | WordPress.org
I need to know how to get back my original uncompressed image database. ... Marc, thanks for reply. ... check that the full...
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