设置请求头:连接
默认情况下,Connection
标头在浏览器中设置为 Keep-Alive
,以便可以为来自浏览器的进一步请求保持连接打开状态。
当我将 Connection
标头设置为 close
时,可能有什么不同? 这会影响任何性能问题吗?
(一补充:我正在从 xmlhttprequest 设置标头)
By default Connection
Header is set to Keep-Alive
in browers, to make it possible to keep connection open for further requests from browser.
When I make Connection
header to close
, what may be the difference ?
Will that affect any performance issue ?
(one addition: I am setting header from xmlhttprequest)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当您使用“连接:保持活动”发出请求时,对服务器的后续请求将使用相同的 TCP 连接。这称为 HTTP 持久连接。这有助于减少服务器端的 CPU 负载并缩短延迟/响应时间。
如果使用“连接:关闭”发出请求,则表示一旦发出请求,服务器就需要关闭连接。因此,对于每个请求,都会建立一个新的 TCP 连接。
默认情况下,HTTP 1.1 客户端/服务器使用 keep-alive,而 HTTP 1.0 客户端/服务器默认不支持 keep-alive。
When you make requests with "Connection: keep-alive" the subsequent request to the server will use the same TCP connection. This is called HTTP persistent connection. This helps in reducing CPU load on the server side and improves latency/response time.
If a request is made with "Connection: close" this indicates that once the request has been made the server needs to close the connection. And so for each request a new TCP connection will be established.
By default HTTP 1.1 client/server uses keep-alive whereas HTTP 1.0 client/server doesn't support keep-alive by default.
它会影响性能,因为最昂贵的资源会在两台机器之间创建套接字。所以客户端每次请求都需要建立一个新的连接。
It affects performance, because most expensive resources create a socket between two machines. So the client needs to establish a new connection in every request.
本文以图形方式演示了当连接标头设置为关闭并保持活动状态时会发生什么。
它帮助我理解它,我希望它也对你有帮助。
连接保持活动的好处
this article has graphically demonstrated what would happen in such a when the connection header is set to closed and also keep-alive.
It helped me understand it and I hope it helps you too.
The Benefits of Connection Keep Alive