Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Request header: Connection

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)

like image 832
ajduke Avatar asked Oct 19 '11 14:10

ajduke


People also ask

What is connection in HTTP header?

The Connection general header controls whether the network connection stays open after the current transaction finishes. If the value sent is keep-alive , the connection is persistent and not closed, allowing for subsequent requests to the same server to be done.

When should I close an HTTP 1.1 connection?

after the current request/response is complete. HTTP/1.1 applications that do not support persistent connections MUST include the "close" connection option in every message.

How do I send a header in HTTP request?

To add custom headers to an HTTP request object, use the AddHeader() method. You can use this method multiple times to add multiple headers.


1 Answers

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.

like image 130
Kannan Mohan Avatar answered Oct 05 '22 07:10

Kannan Mohan