MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

这篇翻译不完整。请帮忙从英语翻译这篇文章

HTTP请求头 Accept-Encoding 通知客户端能够理解的内容编码,通常是一个压缩算法。 通过内容协商的方式,服务端会选择一个客户端提议的方式,使用并在回应报文header的Content-Encoding 中通知客户端该选择。

即使客户机和服务器都支持相同的压缩算法,服务器也可以选择不压缩响应的主体,如果身份值也是可接受的。 两个常见的情况导致:

  • 发送的数据已经被压缩,第二次压缩不会导致更小的数据被传输。这可能会有一些图像格式;
  • 服务器超载,无法承受压缩需求导致的计算开销。通常,如果服务器使用超过80%的计算能力,微软建议不要压缩。

As long as the identity value, meaning no encryption, is not explicitly forbidden, by an identity;q=0 or a *;q=0 without another explicitly set value for identity, the server must never send back a 406 Not Acceptable error.

Notes:
  • An IANA registry maintains a complete list of official content encodings.

  • Two others content encoding, bzip and bzip2, are sometimes used, though not standard. They implement the algorithm used by these two UNIX programs. Note that the first one was discontinued due to patent licensing problems.
Header type Request header
Forbidden header name yes

Syntax

Accept-Encoding: gzip
Accept-Encoding: compress
Accept-Encoding: deflate
Accept-Encoding: br
Accept-Encoding: identity
Accept-Encoding: *

// Multiple algorithms, weighted with the quality value syntax:
Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5

Directives

gzip
A compression format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC.
compress
A compression format using the Lempel-Ziv-Welch (LZW) algorithm.
deflate
A compression format using the zlib structure, with the deflate compression algorithm.
br
A compression format using the Brotli algorithm.
identity
Indicates the identity function (i.e. no compression, nor modification. This value is always considered as acceptable, even if not present.
*
Matches any content encoding not already listed in the header. This is the default value if the header is not present. It doesn't mean that any algorithm is supported; merely that no preference is expressed.
;q= (qvalues weighting)
Any value is placed in an order of preference expressed using a relative quality values called weight.

Examples

Accept-Encoding: gzip

Accept-Encoding: gzip, compress, br

Accept-Encoding: br;q=1.0, gzip;q=0.8, *;q=0.1

Specifications

Specification Title
RFC 7231, section 5.3.4: Accept-Encoding Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

Browser compatibility

FeatureChromeFirefoxEdgeInternet ExplorerOperaSafari
Basic Support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)
FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)

See also

 
 

文档标签和贡献者

标签: 
 此页面的贡献者: WayneCui, felixwang-1989, yt449, xgqfrms-GitHub
 最后编辑者: WayneCui,