Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP is statel-less,so what does it mean by 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?

like image 819
kern Avatar asked May 19 '11 15:05

kern


4 Answers

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

like image 166
Kris Avatar answered Oct 22 '22 14:10

Kris


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

like image 8
spender Avatar answered Oct 22 '22 12:10

spender


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.

like image 4
Pravin Mishra Avatar answered Oct 22 '22 13:10

Pravin Mishra


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.

like image 1
Brian Agnew Avatar answered Oct 22 '22 13:10

Brian Agnew