Keep-Alive

The HTTP Keep-Alive header sets parameters for persistent connections when the Connection header is set to keep-alive. Keep-Alive is an IANA-registered permanent header, part of the HTTP/1.0 and HTTP/1.1 connection model. HTTP/2 and HTTP/3 manage connection persistence through their own mechanisms.

Usage

The Keep-Alive header works alongside the Connection header to fine-tune persistent connection behavior in HTTP/1.1. When a connection is marked as persistent, this header communicates how long the connection remains idle and how many requests the connection handles before closing.

Both clients and servers send this header. A server includes Keep-Alive in a response to inform the client of the connection limits enforced on the server side. A client includes the header to express preferences, though the server is not required to honor them.

Persistent connections reduce latency by avoiding repeated TCP handshakes and, when TLS is involved, repeated TLS negotiations.

Note

The Keep-Alive header applies to HTTP/1.1 connections only. HTTP/2 and HTTP/3 manage connection persistence through their own protocol mechanisms.

Directives

timeout

The timeout parameter specifies the minimum number of seconds the host keeps an idle connection open. An idle connection is one where no data is transmitted in either direction for the specified duration. The host is free to keep the connection open longer than the stated value.

max

The max parameter sets the maximum number of requests the connection accepts before closing. For non-pipelined connections, this parameter is ignored unless the value is 0. The parameter is designed for HTTP pipelining, where multiple requests are sent without waiting for each response.

Example

A server responds with keep-alive parameters, setting a 10-second idle timeout and a limit of 100 requests on the connection. After 100 requests or 10 seconds of inactivity, the server closes the connection.

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

A shorter timeout is common on high-traffic servers to free resources more aggressively. This response allows a 5-second idle window and permits up to 500 requests.

HTTP/1.1 200 OK
Connection: keep-alive
Keep-Alive: timeout=5, max=500

Takeaway

The Keep-Alive header defines idle timeout and request limits for persistent HTTP/1.1 connections, working alongside the Connection header to manage TCP connection reuse.

See also

Last updated: March 11, 2026