HTTP is statel-less,so what does it mean by keep-alive?

扶醉桌前 提交于 2019-12-04 10:31:56

问题


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?


回答1:


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




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/6060959/http-is-statel-less-so-what-does-it-mean-by-keep-alive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!