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/keep-alive/index.html | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 files/zh-cn/web/http/headers/keep-alive/index.html (limited to 'files/zh-cn/web/http/headers/keep-alive') diff --git a/files/zh-cn/web/http/headers/keep-alive/index.html b/files/zh-cn/web/http/headers/keep-alive/index.html new file mode 100644 index 0000000000..afd7bc4111 --- /dev/null +++ b/files/zh-cn/web/http/headers/keep-alive/index.html @@ -0,0 +1,95 @@ +--- +title: Keep-Alive +slug: Web/HTTP/Headers/Keep-Alive +tags: + - HTTP + - HTTP Headers +translation_of: Web/HTTP/Headers/Keep-Alive +--- +
{{HTTPSidebar}}
+ +

Keep-Alive 是一个通用消息头,允许消息发送者暗示连接的状态,还可以用来设置超时时长和最大请求数。

+ +
+

需要将 The {{HTTPHeader("Connection")}} 首部的值设置为  "keep-alive" 这个首部才有意义。同时需要注意的是,在HTTP/2 协议中, {{HTTPHeader("Connection")}} 和 {{HTTPHeader("Keep-Alive")}}  是被忽略的;在其中采用其他机制来进行连接管理。

+
+ + + + + + + + + + + + +
Header type{{Glossary("General header")}}
{{Glossary("Forbidden header name")}}no
+ +

语法

+ +
Keep-Alive: parameters
+ +

指令

+ +
+
parameters
+
一系列用逗号隔开的参数,每一个参数由一个标识符和一个值构成,并使用等号 ('=') 隔开。下述标识符是可用的: +
    +
  • timeout:指定了一个空闲连接需要保持打开状态的最小时长(以秒为单位)。需要注意的是,如果没有在传输层设置 keep-alive TCP message 的话,大于 TCP 层面的超时设置会被忽略。
  • +
  • max:在连接关闭之前,在此连接可以发送的请求的最大值。在非管道连接中,除了 0 以外,这个值是被忽略的,因为需要在紧跟着的响应中发送新一次的请求。HTTP 管道连接则可以用它来限制管道的使用。
  • +
+
+
+ +

示例

+ +

含有 Keep-Alive 首部的响应示例:

+ +
HTTP/1.1 200 OK
+Connection: Keep-Alive
+Content-Encoding: gzip
+Content-Type: text/html; charset=utf-8
+Date: Thu, 11 Aug 2016 15:23:13 GMT
+Keep-Alive: timeout=5, max=1000
+Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
+Server: Apache
+
+(body)
+ +

规范

+ + + + + + + + + + + + + + + + + + + + +
SpecificationTitle
HyperText Transport Protocol Keep-Alive HeaderThe Keep-Alive Header (Experimental specification)
RFC 7230, appendix A.1.2: Keep-AliveHypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing
{{RFC("2068", "The Keep-Alive Header", "19.7.1.1")}}Hypertext Transfer Protocol -- HTTP/1.1
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Keep-Alive")}}

+ +

相关内容

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