非常教程

HTTP参考手册

标题 | Headers

Keep-Alive

非标准

这个功能是非标准的,不在标准轨道上。不要在面向 Web 的生产站点上使用它:它不适用于每个用户。实现之间也可能存在很大的不兼容性,并且行为在未来可能会发生变化。

Keep-Alive一般报头允许发送者提示关于如何连接,并且可以被用于设置超时时间,并且请求的最大数量。

Connection头需要被设置为“保活”这个标题有任何意义。此外,ConnectionKeep-Alive在 HTTP / 2 忽略; 连接管理由其他机制处理。

Header type

General header

Forbidden header name

no

句法

Keep-Alive: parameters

指令

_parameters_ 逗号分隔的参数列表,每个参数都包含由等号('=')分隔的标识符和值。以下标识符是可能的:

  • timeout:指示空闲连接必须保持打开的最短时间(以秒为单位)。请注意,如果在传输级别上未设置保持活动 TCP 消息,则可能会忽略超过 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)

产品规格

Specification

Title

HyperText Transport Protocol Keep-Alive Header

The Keep-Alive Header (Experimental specification)

RFC 7230, section appendix-A.1.2: Keep-Alive

Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

浏览器兼容性

Feature

Chrome

Edge

Firefox

Internet Explorer

Opera

Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Edge mobile

Firefox for Android

IE mobile

Opera Android

iOS Safari

Basic Support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

请参阅

  • Connection
  • HTTP / 1.x 中的连接管理
HTTP

超文本传输协议( HTTP,HyperText Transfer Protocol ) 是互联网上应用最为广泛的一种网络协议。所有的 WWW 文件都必须遵守这个标准。