首页
随机
最近更改
特殊页面
社群首页
参数设置
关于WHY42
免责声明
WHY42
搜索
用户菜单
登录
欢迎来到Riguz的小站!这是一个私人wiki,用来记录一些我的笔记。
查看“︁HTTP keep-alive”︁的源代码
←
HTTP keep-alive
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the same idea and takes it further to allow multiple concurrent requests/responses to be multiplexed over a single connection. = Implementations == == HTTP 1.1 == HTTP1.0 通过在请求头中添加Connection: keep-alive启用长连接(非官方做法),而HTTP 1.1默认使用Keep-Alive机制(也叫持久化连接),可以使得多个HTTP请求共用一个底层的TCP连接。 正常情况下,客户端发送单个HTTP请求后,会发送RST报文主动断开连接: [[Image:http-rst.png|600px|border]] 如果不启用Keep-Alive或者因某种原因没有生效(比如Go语言中没有读取完Body内容时,该连接无法复用),发送多个HTTP请求时会导致多次握手建立连接: [[Image:http-multi-connection.png|600px|border]] 而启用Keep-Alive后,发送多次HTTP请求无需重新握手: [[Image:http-share-connection.png|600px|border]] 当客户端Keep-Alive超时时间小于服务器超时时间时,会发送Keep-Alive报文(ACK): [[Image:http-ack.png|600px|border]] 当服务器Keep-Alive超时时间小于客户端超时时间时,则会主动发送FIN断开连接。再次发送数据时,需要重新握手建立连接: [[Image:http-fin.png|600px|border]] == HTTP 1.1 == == HTTP 2.0 == == See also == * [[HTTP/1.1]] * [[HTTP/2]] [[Category:Network]] [[Category:HTTP]] [[Category:Protocol]] [[Category:RFC]]
返回
HTTP keep-alive
。