92

Is there any way to get curl to decompress a response without sending the Accept-encoding headers in the request?

I'm trying to debug an issue where the order of the Accept-encoding headers may be relevant, but I also need to know what the response is. If I just send -H 'Accept-encoding: gzip and the server gzips the response, curl won't decompress it.

0

2 Answers 2

138

Probably the easiest thing to do is just use gunzip to do it:

curl -sH 'Accept-encoding: gzip' http://example.com/ | gunzip -

Or there's also --compressed, which curl will decompress (I believe) since it knows the response is compressed. But, not sure if that meets your needs.

2
  • 1
    Works like a charm! Any way to get it to work when there are output headers too, or is that asking too much? Commented Oct 7, 2013 at 11:30
  • 5
    @Jun-DaiBates-Kobashigawa You can use -D to dump headers to a file, e.g. -D headers.txt and it will save them to the file out of band so it won't screw up your gzip encoding.
    – FatalError
    Commented Oct 7, 2013 at 15:28
74

curl --compressed http://example.com requests gzipped-compressed data and uncompresses it before writing to disk.

1
  • With the --compressed flag, curl will send an Accept-Encoding: gzip request header. It sounds like that might be fine for what the op wants, but it's not directly satisfying the question. (I found this question because I actually do want curl to decompress without sending the header)
    – Chris
    Commented Jul 18, 2021 at 22:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.