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-al
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.
This means it is OK to keep the connection open to ask for more resources like for example images and stylesheets.
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.
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
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.