Accept-Encoding - HTTP 编辑

The Accept-Encoding request HTTP header advertises which content encoding, usually a compression algorithm, the client is able to understand. Using content negotiation, the server selects one of the proposals, uses it and informs the client of its choice with the Content-Encoding response header.

Even if both the client and the server supports the same compression algorithms, the server may choose not to compress the body of a response, if the identity value is also acceptable. Two common cases lead to this:

  • The data to be sent is already compressed and a second compression won't lead to smaller data to be transmitted. This may be the case with some image formats;
  • The server is overloaded and cannot afford the computational overhead induced by the compression requirement. Typically, Microsoft recommends not to compress if a server uses more than 80% of its computational power.

As long as the identity value, meaning no encoding, 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 typeRequest header
Forbidden header nameyes

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 value 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

SpecificationTitle
RFC 7231, section 5.3.4: Accept-EncodingHypertext Transfer Protocol (HTTP/1.1): Semantics and Context

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:84 次

字数:6181

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文