Content-Encoding - HTTP 编辑

The Content-Encoding entity header is used to compress the media-type. When present, its value indicates which encodings were applied to the entity-body. It lets the client know how to decode in order to obtain the media-type referenced by the Content-Type header.

The recommendation is to compress data as much as possible and therefore to use this field, but some types of resources, such as jpeg images, are already compressed. Sometimes, using additional compression doesn't reduce payload size and can even make the payload longer.

Header typeEntity header
Forbidden header nameno

Syntax

Content-Encoding: gzip
Content-Encoding: compress
Content-Encoding: deflate
Content-Encoding: identity
Content-Encoding: br

// Multiple, in the order in which they were applied
Content-Encoding: gzip, identity
Content-Encoding: deflate, gzip

Directives

gzip
A format using the Lempel-Ziv coding (LZ77), with a 32-bit CRC. This is the original format of the UNIX gzip program. The HTTP/1.1 standard also recommends that the servers supporting this content-encoding should recognize x-gzip as an alias, for compatibility purposes.
compress
A format using the Lempel-Ziv-Welch (LZW) algorithm. The value name was taken from the UNIX compress program, which implemented this algorithm. Like the compress program, which has disappeared from most UNIX distributions, this content-encoding is not used by many browsers today, partly because of a patent issue (it expired in 2003).
deflate
Using the zlib structure (defined in RFC 1950) with the deflate compression algorithm (defined in RFC 1951).
identity
Indicates the identity function (i.e., no compression or modification). This token, except if explicitly specified, is always deemed acceptable.
br
A format using the Brotli algorithm.

Examples

Compressing with gzip

On the client side, you can advertise a list of compression schemes that will be sent along in an HTTP request. The Accept-Encoding header is used for negotiating content encoding.

Accept-Encoding: gzip, deflate

The server responds with the scheme used, indicated by the Content-Encoding response header.

Content-Encoding: gzip

Note that the server is not obligated to use any compression method. Compression highly depends on server settings and used server modules.

Specifications

SpecificationTitle
RFC 7932: Brotli Compressed Data FormatBrotli Compressed Data Format
RFC 7231, section 3.1.2.2: Content-EncodingHypertext Transfer Protocol (HTTP/1.1): Semantics and Content
RFC 2616, section 14.11: Content-EncodingContent-Encoding

Browser compatibility

BCD tables only load in the browser

See also

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

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

发布评论

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

词条统计

浏览:141 次

字数:5386

最后编辑:6 年前

编辑次数:0 次

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