Response is not getting compressed or being corrupted?
See original GitHub issuethis 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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 supportedAccept-Encoding
isgzip
, the response will be compressed ingzip
if it’sdeflate
, the response shall be compressed indeflate
form, and if it’s not mentioned response shall be simple plain data. I was receiving plain text in curl because curl does not sendAccept-Encoding
in its default request, but when I sent curl request usingcurl -H 'Accept-Encoding: gzip' -D - http://localhost:3000
my response was coded into compressed form. So my code has been working for always. ThanksEdit: And you were also right that if
content-encoding
is set, module will not run so we don’t have to explicitly set thecontent-encoding
, it should be set by compression middleware depending onAccept-Encoding
of the requestpull request