【问题标题】:What is the canonical method for an HTTP client to instruct an HTTP server to disable gzip responses?HTTP 客户端指示 HTTP 服务器禁用 gzip 响应的规范方法是什么?
【发布时间】:2012-11-25 01:48:19
【问题描述】:

我以为这是一个简单的谷歌搜索,但显然我错了。

我看到你应该提供:

Accept-Encoding: gzip;q=0,deflate;q=0

在请求标头中。但是,建议它的文章还指出,代理通常会忽略该标头。另外,当我将它提供给 nginx 时,它仍然会压缩响应消息体。

http://forgetmenotes.blogspot.ca/2009/05/how-to-disable-gzip-compression-in.html

那么,我如何告诉 Web 服务器禁用响应消息正文的压缩?

【问题讨论】:

  • 我很困惑:你想从客户端发送指令到服务器,你想要保证通过任何不情愿的代理传递的东西,或者你想要指令告诉服务器在任何情况下都不要压缩?
  • 后者...我希望指令告诉服务器在任何情况下都不要压缩
  • 请注意,为了防止所有压缩,您可能希望使用*;q=0 而不仅仅是禁止 gzip 和 deflate。话虽如此,我确实认为许多服务器并没有理所当然地使用 Accept-Encoding 功能。还有Accept-Encoding: identity...

标签: http compression gzip http-accept-encoding


【解决方案1】:

许多 Web 服务器忽略 'q' 参数。静态资源的压缩版本通常会被缓存,并在请求接受时返回。为避免获得压缩资源,请使用

Accept-Encoding: identity

在这种情况下,服务器不应为您提供资源的压缩表示。也不应该有任何代理。如果没有给出,这是默认接受的编码,但您的客户端可能会添加一个接受 gzip 的默认值,因此明确提供“身份”应该可以解决问题。

【讨论】:

  • 不幸的是,nginx 似乎并不尊重这一点。我仍然可以将内容重新压缩。
  • 请注意,没有Accept-Encoding 不等同于身份。文档清楚地表明,如果没有指定编码,服务器可以决定做什么。
【解决方案2】:

我认为这个模组适用于 apache

http://httpd.apache.org/docs/2.2/mod/mod_deflate.html(2)

这适用于 Nginx

http://wiki.nginx.org/HttpGzipModule(1)

听起来像是您需要的,具体取决于您计划使用的服务器。剩下的就看你自己了!

请注意nginx模块都允许关闭解压:

[edit] gzip 
Syntax: gzip on | off  
Default: off 
Context: http
server
location
if in location 
Reference: gzip 



Enables or disables gzip compression. 

以及处理代理:

[edit] gzip_proxied 
Syntax: gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any ... 
Default: off 
Context: http 
server
location 
Reference: gzip_proxied 



It allows or disallows the compression of the response for the proxy request in the dependence on the request and the response. The fact that, request proxy, is determined on the basis of line "Via" in the headers of request. In the directive it is possible to indicate simultaneously several parameters: 

off - disables compression for all proxied requests 
expired - enables compression, if the "Expires" header prevents caching 
no-cache - enables compression if "Cache-Control" header is set to "no-cache" 
no-store - enables compression if "Cache-Control" header is set to "no-store" 
private - enables compression if "Cache-Control" header is set to "private" 
no_last_modified - enables compression if "Last-Modified" isn't set 
no_etag - enables compression if there is no "ETag" header 
auth - enables compression if there is an "Authorization" header 
any - enables compression for all requests 
[edit] gzip_types 

祝你好运!

来源:

1) http://forum.nginx.org/read.php?11,96472,214303

2)http://httpd.apache.org/docs/2.2/mod/mod_deflate.html#inflate(段输出解压)

【讨论】:

    【解决方案3】:

    您希望完全禁用编码吗?
    然后跳过 http 请求标头中的 Accept-Encoding 标头本身。

    您是否希望 http 响应中只缺少 gzip 压缩?
    然后从 http 请求标头中的值列表中跳过 gzip。

    您希望优先考虑服务器支持的不同压缩技术吗?然后对 Accept-Encoding http 请求标头中的每个值使用 0 和 1 之间的不同值以及 q 参数。 (目前您正在使用冲突值并通过 weight=0 表示您不知道如何管理,但您希望响应被编码)

    【讨论】:

    • 为了让代理考虑从其缓存提供的内容的 Accept-Encoding http 标头,Vary http Response 标头与 HTTP 请求标头(例如 Accept-Encoding)一起用作其值列表,因此代理知道缓存要提供的副本因 http 请求标头而异。
    • 不不不。 W3C 规范 (w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3) 明确指出“如果请求中不存在 Accept-Encoding 字段,则服务器可以假设客户端将接受任何内容编码。”还有“注意:如果请求不包含 Accept-Encoding 字段,并且如果“身份”内容编码不可用,那么 HTTP/1.0 客户端通常理解的内容编码(即“gzip”和“compress”)是首选;"
    • tools.ietf.org/html/rfc2616#section-14.3 你错过了中间句“在这种情况下,如果“身份”是可用的内容编码之一,那么服务器应该使用“身份”内容编码,除非它有附加信息,说明不同的内容编码对客户端有意义。”,因此该注释最多只是最后的手段。此外,IETF 是包括 http 在内的互联网协议的规范权威,在此答案时 http1.1 是规范。对于像您这样的好奇和边缘情况,我猜想在此评论中提及链接就足够了。
    • 我的观点是,确保 GZIP 响应被禁用的规范方法是指定 Accept-encoding: 身份。据我所知,任何其他响应(包括您根本不传递 Accept-encoding 标头的响应)都可能不起作用。
    • 根据 IETF 标准引用的句子,您对规范“方式”的假设与meta.stackexchange.com/questions/66377/what-is-the-xy-problem 相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 2020-06-26
    • 1970-01-01
    相关资源
    最近更新 更多