The HTTP Connection header is a general type header that allows the sender or client to specify options that are desired for that particular connection. Instead of opening a new connection for every single request/response, Connection helps in sending or receiving multiple HTTP requests/responses using a single TCP connection. It also controls whether or not the network stays open or close after the current transaction finishes.
Connection: keep-alive Connection: close
Directives: This HTTP Connection header accept two directives mentioned above and described below:
- keep-alive This directive indicates that the client wants to keep the connection open or alive after sending the response message. In HTTP 1.1 version, by default uses a persistent connection where it doesn’t close automatically after a transaction. But the HTTP 1.0 will not consider the connections as persistent, so if you want to keep it alive, you need to include a keep-alive connection header.
- close This close connection directive indicates that the client wants to close the connection after sending the response message. In HTTP 1.0, by default, the connection gets closed. But in HTTP 1.1, you need to include it in the header if you want your connection to close.
Note: Both the directives are also headers that represent the connection in combine.
- Here, in the below example, the connection is keep-alive (i.e) the client wants to keep it open and the value is 100. Usually, the value 100 is sufficient for almost every scenario. However, you can increase it depending on the number of files the server needs to deliver within the web page.
Keep-Alive: 100 Connection: keep-alive
- The below example is the request message sent by a client in which it wants the connection to close after the response message is delivered.
Browser Compatibility: The browsers are compatible with HTTP Connection header are listed below:
- HTTP headers | Access-Control-Expose-Headers
- HTTP headers | Access-Control-Allow-Headers.
- HTTP headers | Age
- HTTP headers | Allow
- HTTP headers
- HTTP headers | Via
- HTTP Headers | TE
- HTTP headers | Expect
- HTTP headers | Set-Cookie2
- HTTP headers | Origin
- HTTP headers | Trailer
- HTTP headers | X-Forwarded-For
- HTTP headers | Want-Digest
- HTTP headers | If-None-Match
- HTTP headers | Accept
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.