HTTP headers | Keep-Alive

The Keep-Alive header is a general-type header. This header is used to hint at how the connection may be used to set a timeout and a maximum amount of requests. It can also be used to allow a single TCP connection to remain open for multiple HTTP requests/responses (default HTTP connection closed after each request). It is also known as a persistent connection. Enabling keep-alive totally depends on what server you are using and what access you have.

Syntax:

Keep-Alive: parameters

Directives: This header accepts a single directive as mentioned above and described below:



  • Parameters: This directive holds two comma-separated parameters timeout and max. The timeout parameter holds the minimum amount of time which is the time(in seconds) of connection has to be kept open. The ax parameter holds an integer number define how the number of requests can be sent to this connection before closing the connection.

Example: In this example connection header has to set on Keep-Alive.

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 17 Feb 2020 18:23:13 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Mon, 17 Feb 2020 04:32:39 GMT
Server: Apache

To check this Keep-Alive in action go to Inspect Element -> Network check the header for Keep-ALive like below.
Keep-Alive General header

Supported Browsers: The browsers compatible with HTTP header Keep-Alive are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.