🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Keep Alive

HTTP Header

The HTTP Keep-Alive request and response headers enable the sender to suggest how a connection should be maintained, including specifying a timeout period and a maximum number of requests.

HTTP/1.0 closes the connection after each request-response cycle by default, requiring explicit negotiation for persistent connections.
Some clients and servers aim for compatibility with earlier persistent connection methods by including the Connection: keep-alive header in requests.
Additional parameters for the connection, such as timeout and maximum requests, can be requested using the Keep-Alive header.

Syntax

Keep-Alive: <parameters>

Directives

A comma-separated list of parameters, each consisting of an identifier and a value separated by the equal sign (=).
The following identifiers are possible:

timeout
An integer that specifies the duration in seconds before the host closes an idle connection. A connection is considered idle if no data is sent or received. While a host can keep an idle connection open longer than this timeout, it should aim to retain the connection for at least this duration.
max
An integer indicating the maximum number of requests allowed on this connection before it is closed. Unless set to 0, this limit is ignored for non-pipelined connections, where another request can be sent in the next response. This setting can be used to control pipelining in HTTP.

Example

A response containing a Keep-Alive header:

http
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Aug 2016 15:23:13 GMT
Keep-Alive: timeout=5, max=200
Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
Server: Apache

(body)

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Keep-Alive header. This is especially useful for testing how your application handles persistent connections and to troubleshoot connection management issues. Steps to Modify the Keep-Alive Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter Keep-Alive.
    • In the “Header Value” field, enter your desired configuration (e.g., timeout=5, max=100).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. Save the rule.

Once set up, Requestly will inject the Keep-Alive header with your specified values into all matching requests, enabling you to test and optimize how your application manages persistent HTTP connections.

Modifying the Keep-Alive header is helpful because it controls how long a connection stays open between client and server. This can improve performance by reducing connection overhead or help debug connection timeout issues.