48

This encoding header tells a web server to send gzip content if available.

'accept-encoding': 'gzip,deflate,sdch',

How can I instruct the web server to send plain text and not gzip the content? I am aware that the web server can simply ignore this request if it wanted to.

Brad Koch
  • 19,267
  • 19
  • 110
  • 137
saeed
  • 3,861
  • 3
  • 25
  • 23
  • 3
    this might be just a really naive answer, but shouldn't you just remove the 'gzip' entry from that list of accepted encodings? – J. Ed Sep 07 '12 at 15:50
  • 1
    wouldn't that leave to web-server to decide if to gzip or not? I want to explicity say don't send gzip content. – saeed Sep 07 '12 at 15:52
  • 2
    No. If you don't 'accept' gzip, the server may not send gzip. – bmargulies Sep 07 '12 at 15:53
  • @saeed If it's in the accept-encoding, it's up to the server to decide, if it's not, it's not allowed. – Joachim Isaksson Sep 07 '12 at 15:53
  • 2
    Can someone get this link to return something other than gzip? http://regnskaber.virk.dk/83177682/ZG9rdW1lbnRsYWdlcjovLzAzL2ZkLzBhL2YxL2RlLzMxOTEtNGEyZi04ZTMyLTVjYTY1MzY0OGQ3Yg.xml Chrome will accept gzip by default. If I try from curl `curl "http://regnskaber.virk.dk/83177682/ZG9rdW1lbnRsYWdlcjovLzAzL2ZkLzBhL2YxL2RlLzMxOTEtNGEyZi04ZTMyLTVjYTY1MzY0OGQ3Yg.xml" -H "Pragma: no-cache" -H "Accept-Encoding: deflate, sdch" ` I don't get back the plain XML I expect. Nor if I try `... -H "Accept-Encoding: identity" ...` – Nate Anderson Jun 14 '16 at 23:44

2 Answers2

80

Not including the accept-encoding header implies that you may want the default encoding, i.e. identity. The caveat here is that the RFC2616 sec 14.3 allows the server to assume any available encoding is acceptable.

To explicitly request plain text, set 'accept-encoding: identity'

Community
  • 1
  • 1
dude
  • 801
  • 1
  • 6
  • 2
  • 4
    This is the only answer that worked for me. Leaving the encoding out did not help. – Andreas Apr 02 '15 at 13:34
  • Have you encountered a response with no `content-encoding` headers? – Will May 05 '16 at 14:59
  • 1
    Will> i had the same issue, and my server replied gzip content if no encoding were specified (the said server was a Tomcat 8). The "identity" encoding solved my pb. – pataluc Mar 21 '17 at 12:57
  • Tested this myself on `http://ismycomputeron.com`, a website that likes to use gzip/deflate, with telnet, and it works. – Robert Moore Apr 12 '17 at 19:31
26

Leaving the encoding out of accept-encoding will disallow that encoding (ie gzip).

If you want to explicitly set it as disallowed, you can set a qvalue of 0.

'accept-encoding': 'gzip;q=0,deflate,sdch'

You can read more under accept-encoding in RFC2616, but in short if the server can't find an acceptable encoding among the ones listed (identity being a special case, see the link), it should send a 406 (Not Acceptable) response and not reply to your request with any other encoding.

Brad Koch
  • 19,267
  • 19
  • 110
  • 137
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 2
    Leaving out the gzip string did work on the server am working with but qvaule did not. I guess it depends on the server and how its configured. – saeed Sep 07 '12 at 16:09
  • The [busybox httpd](https://git.busybox.net/busybox/tree/networking/httpd.c#n2356) is an example of a server not supporting the qvalue, so for some embedded devices, `gzip;q=0` wont work. – Mira Weller Nov 22 '17 at 15:48