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.
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.
Supported Browsers: The browsers compatible with HTTP header Keep-Alive are listed below:
- Google Chrome
- Internet Explorer
- HTTP headers | Access-Control-Request-Headers
- HTTP headers | Access-Control-Expose-Headers
- HTTP headers | Access-Control-Allow-Headers.
- HTTP headers | Age
- HTTP Headers | TE
- HTTP headers | Allow
- HTTP headers
- HTTP headers | Alt-Svc
- HTTP headers | DNT
- HTTP headers | From
- HTTP headers | Via
- HTTP headers | Tk
- HTTP headers | Digest
- HTTP headers | Retry-After
- HTTP headers | Range
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.