From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/http/headers/accept-encoding/index.html | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 files/zh-cn/web/http/headers/accept-encoding/index.html (limited to 'files/zh-cn/web/http/headers/accept-encoding') diff --git a/files/zh-cn/web/http/headers/accept-encoding/index.html b/files/zh-cn/web/http/headers/accept-encoding/index.html new file mode 100644 index 0000000000..f2379df8d1 --- /dev/null +++ b/files/zh-cn/web/http/headers/accept-encoding/index.html @@ -0,0 +1,117 @@ +--- +title: Accept-Encoding +slug: Web/HTTP/Headers/Accept-Encoding +tags: + - Accept-Encoding + - 内容协商 + - 请求头 +translation_of: Web/HTTP/Headers/Accept-Encoding +--- +
{{HTTPSidebar}}
+ +

HTTP 请求头 Accept-Encoding 会将客户端能够理解的内容编码方式——通常是某种压缩算法——进行通知(给服务端)。通过内容协商的方式,服务端会选择一个客户端提议的方式,使用并在响应头 {{HTTPHeader("Content-Encoding")}} 中通知客户端该选择。

+ +

即使客户端和服务器都支持相同的压缩算法,在 identity 指令可以被接受的情况下,服务器也可以选择对响应主体不进行压缩。导致这种情况出现的两种常见的情形是:

+ + + +

只要 identity —— 表示不需要进行任何编码——没有被明确禁止使用(通过 identity;q=0 指令或是 *;q=0 而没有为 identity 明确指定权重值),则服务器禁止返回表示客户端错误的 {{HTTPStatus("406")}} Not Acceptable 响应。

+ +
注意: + + +
+ + + + + + + + + + + + +
Header type{{Glossary("Request header")}}
{{Glossary("Forbidden header name")}}yes
+ +

语法

+ +
Accept-Encoding: gzip
+Accept-Encoding: compress
+Accept-Encoding: deflate
+Accept-Encoding: br
+Accept-Encoding: identity
+Accept-Encoding: *
+
+// Multiple algorithms, weighted with the {{Glossary("Quality Values", "quality value")}} syntax:
+Accept-Encoding: deflate, gzip;q=1.0, *;q=0.5
+ +

指令

+ +
+
gzip
+
表示采用 Lempel-Ziv coding (LZ77) 压缩算法,以及32位CRC校验的编码方式。
+
compress
+
采用 Lempel-Ziv-Welch (LZW) 压缩算法。
+
deflate
+
采用 zlib 结构和 deflate 压缩算法。
+
br
+
表示采用 Brotli 算法的编码方式。
+
identity
+
用于指代自身(例如:未经过压缩和修改)。除非特别指明,这个标记始终可以被接受。
+
*
+
匹配其他任意未在该请求头字段中列出的编码方式。假如该请求头字段不存在的话,这个值是默认值。它并不代表任意算法都支持,而仅仅表示算法之间无优先次序。
+
;q= (qvalues weighting)
+
值代表优先顺序,用相对质量价值 表示,又称为权重。
+
+ +

示例

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

规范

+ + + + + + + + + + + + +
SpecificationTitle
{{RFC("7231", "Accept-Encoding", "5.3.4")}}Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Accept-Encoding")}}

+ +

相关内容

+ + + +
+ +
-- cgit v1.2.3-54-g00ecf