Keep-Alive HTTP Header: Syntax, Directive, Examples

The Keep-Alive HTTP Header general-header allows the sender to specify how the connection should be used, such as setting a timeout and a maximum number of requests. If you want this header to have any effect, you must set the Connection header to Keep-Alive HTTP Header. The Connection general header determines whether or not the network connection will be kept open after the current transaction has been completed successfully. If the Keep-Alive HTTP Header is used, the connection is permanent and is not closed, allowing for additional requests to the same server. There is only one value for using the Keep-Alive HTTP Header. The value for using the Keep-Alive HTTP Header is the parameters. An example of the Keep-Alive HTTP Header is written below.

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Sep 2016 15:27:13 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Mon, 14 Jul 2016 04:32:39 GMT
Server: Apache
(body)

In this article, the Keep-Alive HTTP Header Syntax, Directives, and Uses example will be processed.

What is Keep-Alive HTTP Header?

Keep-Alive is a general type of header. This header indicates the possibility of using the connection to define a timeout and a maximum number of requests. Additionally, it can be used to maintain an open TCP connection for numerous HTTP requests/responses using a single TCP connection (default HTTP connection closed after each request). It is also referred to as a persistent connection. Enabling keep-alive is entirely dependent on the server and the level of access you have.

What is the Syntax of Keep-Alive HTTP Header?

The Keep-Alive HTTP Header uses only one value in its syntax. The syntax for using the Keep-Alive HTTP Header is written below.

Keep-Alive: parameters

What is the Directive of Keep-Alive HTTP Header?

The Keep-Alive HTTP Header can only contain one directive. The parameter specifies a comma-separated list of parameters, each of which contains an identifier and a value separated by the equal sign (‘=’). The following are examples of potential identifiers.

timeout: An integer indicating how long the host will allow an idle connection to remain open before closing it. If a host does not send or receive data, the connection is considered idle. While a host may leave an idle connection open for longer than the timeout period, the host should make an attempt to retain the connection for at least the timeout period.

max: The maximum number of requests that can be sent over this connection before it is closed. Unless set to 0, this value is disregarded for non-pipelined connections, as the following response will contain another request. It can be used to restrict the pipelining in an HTTP pipeline.

An example directive for using the Keep-Alive HTTP Header is given below.

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

How to use Keep-Alive HTTP Header?

The Keep-Alive HTTP Header header is a general-type header that can be used for anything. This header indicates how the connection can be used to provide a timeout and a maximum number of requests. It’s also possible to utilize it to keep a single TCP connection active for many HTTP requests/responses (default HTTP connection closed after each request). A persistent connection is another name for it. Whether or not you should enable keep-alive is entirely dependent on the server you’re using and the level of access you have

Examples of Keep-Alive HTTP Header Use

The following is an example of how to use the Keep-Alive HTTP Header. In this case, the connection header must be configured to Keep-Alive HTTP Header.

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Wed, 22 Jun 2020 15:23:33 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Fri, 13 Mar 2020 06:32:25 GMT
Server: Apache

What is the Specification Document for Keep-Alive HTTP Header?

There is only one specification document for the Keep-Alive HTTP Header which is the RFC 7230. The RFC 7230 section A.1.2. mentions the Keep-Alive HTTP Header connections. It also describes the definition and uses of the Keep-Alive HTTP Header. 

What is the type of Keep-Alive HTTP Header?

The Keep-Alive HTTP Header is a Request Header Type because it indicates how the connection can be used to specify a timeout and a maximum number of requests.

What are the similar HTTP Headers to the Keep-Alive HTTP Header?

There are other similar HTTP to the Keep-Alive HTTP Header. An example is listed below. 

  • Connection HTTP Header: The Connection HTTP Header specifies whether or not the network connection should be kept open after the current transaction has been completed. If keep-alive is used, the connection is permanent and is not closed, allowing for additional requests to the same server. Comparable to the Keep-Alive HTTP Header, which is likewise a sort of general-header.
  • Connection management in HTTP/1.x: Connection management is a critical aspect of HTTP: it has a significant impact on the performance of Web pages and Web applications. There are many models in HTTP/1.x: temporary connections, persistent connections, and HTTP pipelining, which is similar to the Keep-Alive HTTP Header.

Which Browsers Support Keep-Alive HTTP Header?

There are multiple browsers that support Keep-Alive HTTP Header. The following browsers are listed below.

  • Chrome Browser is compatible with the Keep-Alive HTTP Header.
  • Edge Browser is compatible with the Keep-Alive HTTP Header.
  • Firefox Browser is compatible with the Keep-Alive HTTP Header.
  • Internet Explorer Browser is compatible with the Keep-Alive HTTP Header.
  • Opera Browser is compatible with the Keep-Alive HTTP Header.
  • Safari Browser is compatible with the Keep-Alive HTTP Header.
  • WebView Android Browser is compatible with the Keep-Alive HTTP Header.
  • Chrome Android Browser is compatible with the Keep-Alive HTTP Header.
  • Firefox for Android Browser is compatible with the Keep-Alive HTTP Header.
  • Opera Android Browser is compatible with the Keep-Alive HTTP Header.
  • Safari on iOS Browser is compatible with the Keep-Alive HTTP Header.
  • Samsung Internet Browser is compatible with the Keep-Alive HTTP Header.

You can see an image that shows cross-browsers compatibility of Keep-Alive HTTP Headers below. 

Keep-Alive HTTP Header
Holistic SEO
Follow SEO

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.