HTTP是无状态的,那么keep-alive是什么意思呢?
Keep-Alive: 300
Proxy-Connection: keep-alive
我们知道HTTP连接在请求得到响应时关闭,那么keep-alive
是什么意思,有人可以详细说明一下吗?
Keep-Alive: 300
Proxy-Connection: keep-alive
As we know HTTP connection is closed when the request gets responded,so what does it mean by keep-alive
,can someone elaborate this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
什么是 HTTP 连接?实际上,它是一个实现 HTTP 的套接字连接。仅在 HTTP1.0 中,连接才会在每次响应后关闭。为了节省建立 TCP/IP 连接的成本,HTTP1.1 指定除非客户端发送标头
或服务器返回相同的标头,否则套接字将保持打开状态。您可以将任意数量的请求输入此套接字,响应将按照请求的顺序返回。这要求响应要么使用分块传输编码发送,要么包含内容长度标头,以便可以检测/计算每个响应的结尾。
proxy-connection
标头又不同了,它仅与客户端和代理服务器之间的对话相关。我推荐此页面作为该协议的优秀指南。
HTTP 变得非常简单
What is an HTTP connection? Actually, it's a socket connection over which HTTP is implemented. Only in HTTP1.0 does the connection get closed after each response. In order to save on the cost of setting up a TCP/IP connection, HTTP1.1 specifies that unless the client sends a header
or the server comes back with the same header, then the socket remains open. You can feed as many requests as you want into this socket and the responses will come back in the order that they were requested. This requires that the response is either sent with a chunked transfer encoding or contains a content-length header so that the end of each response can be detected/calculated.
The
proxy-connection
header is different again, and is related only to the conversation between client and proxy servers.I'd recommend this page as an excellent guide to the protocol.
HTTP Made Really Easy
这个问题已经被回答并接受了,但我想详细解释一下:
在HTTP/1.1中,默认使用Keep-alive。如果客户端有其他请求,他们将使用相同的连接。
This question is already answered and accepted, but I would like to explain in details:
In HTTP/1.1, Keep-alive is used by default. If clients have additional requests, they will use the same connection for them.
该协议确实是无状态的,但 keep-alive 表示客户端和服务器之间的连接应保持打开状态。
打开 TCP 连接是一个相对重量级的操作,保持该连接打开可以避免与打开新连接相关的设置和拆除成本。
The protocol is indeed stateless, but keep-alive indicates that the connection should be kept open between the client and server.
Opening a TCP connection is a relatively heavyweight operation, and keeping that connection open avoids the setup and teardown cost associated with opening a new connection.
Keep-alive
与状态性无关。在网络中,成本最高的操作之一是重复打开和关闭连接。然而,现代 HTML 页面从技术上要求您精确地执行以下操作:首先获取页面,然后获取每个资源并重复,直到获得所有内容。由于这会非常慢,HTTP/1.1 允许代理保持连接活动,直到他从服务器获得他想要的一切。
Keep-alive
基本上是网络浏览器告诉服务器不要挂断。Keep-alive
has nothing to do with statefulness.In networking, one of the costliest operation is repeatedly opening and closing connections. Modern HTML pages, however, technically ask you to do precisely that: First, get the page, then get each resource and repeat until you have everything. Since that would be incredibly slow, HTTP/1.1 allows agents to keep the connection alive until he ahs everything he wants from the server.
Keep-alive
is basically the web browser telling the server not to hang up yet.这意味着可以保持连接打开以请求更多资源,例如图像和样式表。
This means it is OK to keep the connection open to ask for more resources like for example images and stylesheets.