Keep-Alive 头
HTTP Keep-Alive
请求和响应头允许发送方提示连接在超时和最大请求量方面的使用方式。
注意:要使 Keep-Alive
生效,消息还必须包含 Connection: keep-alive
头。
HTTP/1.0 默认在每次请求/响应交互后关闭连接,因此 HTTP/1.0 中的持久连接必须明确协商。一些客户端和服务器可能希望与以前的持久连接方法兼容,可以通过 Connection: keep-alive
请求头来实现。可以使用 Keep-Alive
头请求连接的附加参数。
警告:在 HTTP/2 和 HTTP/3 中,禁止使用连接特定的头字段,例如 Connection
和 Keep-Alive
。Chrome 和 Firefox 在 HTTP/2 响应中忽略它们,但 Safari 符合 HTTP/2 规范要求,并且不加载任何包含它们的响应。
语法
http
Keep-Alive: <parameters>
指令
示例
包含 Keep-Alive
头的响应
http
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=200
Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
Server: Apache
(body)
规范
规范 |
---|
HTTP/1.1 # 兼容 http 1.0 持久连接 |
浏览器兼容性
加载中…