Keep-Alive

The HTTP Keep-Alive header is used to specify parameters when the HTTP Connection header is set to keep-alive.

Usage

The Keep-Alive header is referenced only when the HTTP Connection header is set to keep-alive. It includes parameters to govern the idle timeout and the maximum number of HTTP requests. There are two directives: timeout and max.

timeout

The timeout directive refers to the number of seconds that the host will leave the HTTP Connection intact before closing it. In this context, an idle HTTP connection is one where no data is transmitted by either side for the specified period. The host can optionally leave the HTTP connection open for longer than the specified number of seconds.

timeout=<seconds>

max

The max directive specifies the maximum number of HTTP requests that can be processed on the HTTP Connection before it is closed. This directive is ignored for non-pipelined HTTP connections unless the value is 0, as it is intended for an HTTP pipeline to limit pipelining.

max=<maximum # of requests>

Example

In this example, the idle timeout is set to ten seconds and it can accept up to 100 HTTP requests before the HTTP Connection is forcibly closed.

Response

HTTP/1.1 200 OK
Connection: keep-alive
Content-Type: text/html; chartset=utf-8
Keep-Alive: timeout=10, max=100

Takeaway

The Keep-Alive header is used to supply relevant HTTP connection-related parameters when the HTTP Connection header is present.

See also

Last updated: June 2, 2022