HTTP是无状态的,那么keep-alive是什么意思呢?

发布于 2024-11-08 15:07:16 字数 142 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

云淡风轻 2024-11-15 15:07:17

众所周知,当请求得到响应时,HTTP 连接就会关闭

什么是 HTTP 连接?实际上,它是一个实现 HTTP 的套接字连接。仅在 HTTP1.0 中,连接才会在每次响应后关闭。为了节省建立 TCP/IP 连接的成本,HTTP1.1 指定除非客户端发送标头

Connection:close

或服务器返回相同的标头,否则套接字将保持打开状态。您可以将任意数量的请求输入此套接字,响应将按照请求的顺序返回。这要求响应要么使用分块传输编码发送,要么包含内容长度标头,以便可以检测/计算每个响应的结尾。

proxy-connection 标头又不同了,它仅与客户端和代理服务器之间的对话相关。

我推荐此页面作为该协议的优秀指南。

HTTP 变得非常简单

As we know HTTP connection is closed when the request gets responded

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

Connection:close

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

你与昨日 2024-11-15 15:07:17

这个问题已经被回答并接受了,但我想详细解释一下:

Keep-alive不能永远维持一个连接;应用程序
在服务器中运行决定了保留的限制
连接处于活动状态,并且在大多数情况下您可以配置此限制。

在HTTP/1.1中,默认使用Keep-alive。如果客户端有其他请求,他们将使用相同的连接。

术语无状态并不意味着服务器没有能力保留
一个连接。这仅仅意味着服务器无法识别任何
任意两个请求之间的关系。

This question is already answered and accepted, but I would like to explain in details:

Keep-alive cannot maintain one connection forever; the application
running in the server determines the limit with which to keep the
connection alive for, and in most cases you can configure this limit.

In HTTP/1.1, Keep-alive is used by default. If clients have additional requests, they will use the same connection for them.

The term stateless doesn't mean that the server has no ability to keep
a connection. It simply means that the server doesn't recognize any
relationships between any two requests.

勿忘初心 2024-11-15 15:07:17

该协议确实是无状态的,但 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.

世态炎凉 2024-11-15 15:07:17

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-aliveis basically the web browser telling the server not to hang up yet.

找回味觉 2024-11-15 15:07:16

这意味着可以保持连接打开以请求更多资源,例如图像和样式表。

This means it is OK to keep the connection open to ask for more resources like for example images and stylesheets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文