From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/http/headers/index.html | 550 ++++++++++++++++++++++++++++++++ 1 file changed, 550 insertions(+) create mode 100644 files/zh-cn/web/http/headers/index.html (limited to 'files/zh-cn/web/http/headers/index.html') diff --git a/files/zh-cn/web/http/headers/index.html b/files/zh-cn/web/http/headers/index.html new file mode 100644 index 0000000000..46b0f9df66 --- /dev/null +++ b/files/zh-cn/web/http/headers/index.html @@ -0,0 +1,550 @@ +--- +title: HTTP Headers +slug: Web/HTTP/Headers +tags: + - HTTP Headers +translation_of: Web/HTTP/Headers +--- +

{{ HTTPSidebar }}

+ +

HTTP 消息头允许客户端和服务器通过 request response传递附加信息。一个请求头由名称(不区分大小写)后跟一个冒号“:”,冒号后跟具体的值(不带换行符)组成。该值前面的引导空白会被忽略。

+ +

自定专用消息头可通过'X-' 前缀来添加;但是这种用法被IETF在2012年6月发布的 RFC5548 中明确弃用,原因是其会在非标准字段成为标准时造成不便;其他的消息头在 IANA 注册表 中列出, 其原始内容在 RFC 4229 中定义。 此外,IANA 还维护着被提议的新HTTP 消息头注册表.

+ +

根据不同上下文,可将消息头分为:

+ + + +

消息头也可以根据代理对其的处理方式分为:

+ +

端到端消息头

+ +

这类消息头必须被传输到最终的消息接收者,也即,请求的服务器或响应的客户端。中间的代理服务器必须转发未经修改的端到端消息头,并且必须缓存它们。

+ +

逐跳消息头

+ +

这类消息头仅对单次传输连接有意义,不能通过代理或缓存进行重新转发。这些消息头包括 {{ httpheader("Connection") }}, {{ httpheader("Keep-Alive") }}, {{ httpheader("Proxy-Authenticate") }}, {{ httpheader("Proxy-Authorization") }}, {{ httpheader("TE") }}, {{ httpheader("Trailer") }}, {{ httpheader("Transfer-Encoding") }} 及 {{ httpheader("Upgrade") }}。注意,只能使用 {{ httpheader("Connection") }} 来设置逐跳一般头。

+ +

左侧导航栏提供了按字母顺序排列的列表。以下列清单概括了消息头及其用途:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
消息头描述更多信息标准
Accept用户代理期望的MIME 类型列表HTTP Content NegotiationHTTP/1.1
Accept-CH +

{{non-standard_inline}}

+
列出配置数据,服务器可据此来选择适当的响应。HTTP Client Hints
Accept-Charset列出用户代理支持的字符集。HTTP Content NegotiationHTTP/1.1
Accept-FeaturesHTTP Content NegotiationRFC 2295, §8.2
Accept-Encoding列出用户代理支持的压缩方法。HTTP Content NegotiationHTTP/1.1
Accept-Language列出用户代理期望的页面语言。HTTP Content NegotiationHTTP/1.1
Accept-Ranges
Access-Control-Allow-CredentialsHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Allow-OriginHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Allow-MethodsHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Allow-HeadersHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Max-AgeHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Expose-HeadersHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("2") }}W3C Cross-Origin Resource Sharing
Access-Control-Request-MethodHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Access-Control-Request-HeadersHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}W3C Cross-Origin Resource Sharing
Age
Allow
AlternatesHTTP Content NegotiationRFC 2295, §8.3
Authorization包含用服务器验证用户代理的凭证
Cache-ControlHTTP Caching FAQ
Connection
Content-Encoding
Content-Language
Content-Length
Content-Location
Content-MD5{{ unimplemented_inline("232030") }}
Content-Range
Content-Security-Policy控制用户代理在一个页面上可以加载使用的资源。CSP (Content Security Policy)W3C Content Security Policy
Content-Type指示服务器文档的MIME 类型。帮助用户代理(浏览器)去处理接收到的数据。
CookieRFC 2109
DNT设置该值为1, 表明用户明确退出任何形式的网上跟踪。Supported by Firefox 4, Firefox 5 for mobile, IE9, and a few major companies.{{SpecName("Tracking")}}
Date
ETagHTTP Caching FAQ
Expect
ExpiresHTTP Caching FAQ
From
Host
If-Match
If-Modified-SinceHTTP Caching FAQ
If-None-MatchHTTP Caching FAQ
If-Range
If-Unmodified-Since
Last-Event-ID给出服务器在先前HTTP连接上接收的最后事件的ID。用于同步文本/事件流。Server-Sent EventsServer-Sent Events spec
Last-ModifiedHTTP Caching FAQ
Link +

等同于HTML标签中的"link",但它是在HTTP层上,给出一个与获取的资源相关的URL以及关系的种类。

+
+

For the rel=prefetch case, see Link Prefetching FAQ

+
+

Introduced in HTTP 1.1's RFC 2068, section 19.6.2.4, it was removed in the final HTTP 1.1 spec, then reintroduced, with some extensions, in RFC 5988

+
Location
Max-Forwards
NegotiateHTTP Content NegotiationRFC 2295, §8.4
OriginHTTP Access Control and Server Side Access Control{{ gecko_minversion_inline("1.9.1") }}More recently defined in the Fetch spec (see Fetch API.) Originally defined in W3C Cross-Origin Resource Sharing
Pragmafor the pragma: nocache value see HTTP Caching FAQ
Proxy-Authenticate
Proxy-Authorization
Range
Referer +

(请注意,在HTTP / 0.9规范中引入的正交错误必须在协议的后续版本中保留)

+
Retry-After
Sec-Websocket-Extensions Websockets
Sec-Websocket-Key Websockets
Sec-Websocket-Origin Websockets
Sec-Websocket-Protocol Websockets
Sec-Websocket-Version Websockets
Server
Set-CookieRFC 2109
Set-Cookie2RFC 2965
Strict-Transport-SecurityHTTP Strict Transport SecurityIETF reference
TCNHTTP Content NegotiationRFC 2295, §8.5
TE
Trailer +

列出将在消息正文之后在尾部块中传输的头。这允许服务器计算一些值,如Content-MD5:在传输数据时。请注意,Trailer:标头不得列出Content-Length :, Trailer:或Transfer-Encoding:headers。

+
RFC 2616, §14.40
Transfer-Encoding
Upgrade
User-Agentfor Gecko's user agents see the User Agents Reference
Variant-VaryHTTP Content NegotiationRFC 2295, §8.6
Vary +

列出了用作Web服务器选择特定内容的条件的标头。此服务器对于高效和正确缓存发送的资源很重要。

+
HTTP Content Negotiation & HTTP Caching FAQ
Via
Warning
WWW-Authenticate
X-Content-DurationConfiguring servers for Ogg media
X-Content-Security-PolicyUsing Content Security Policy
X-DNSPrefetch-ControlControlling DNS prefetching
X-Frame-OptionsThe XFrame-Option Response Header
X-Requested-With +

通常在值为“XMLHttpRequest”时使用

+
Not standard
+ +

注意

+ +
+

注意:{{Gecko ("5.0") }}不会发送带有Keep-Alive的请求头。以前的版本确实发送过,但格式并不正确,因此决定暂时删除它。{{ httpheader("Connection") }}或{{ httpheader("Proxy-Connection") }}报文首部仍然会发送,带着"keep-alive"的值。

+
+ +

更多

+ +

维基百科上对HTTP首部的展示

-- cgit v1.2.3-54-g00ecf