Keep-AliveKeep-Alive conveys parameters that fine-tune how a persistent connection is maintained — hints about how long (timeout) and for how many requests (max) the connection may be reused.
HTTP/1.1 keeps connections alive by default, and this header is used with `Connection: keep-alive` to specify the details (e.g. `Keep-Alive: timeout=5, max=1000`).
Establishing TCP/TLS connections is expensive, so persistent connections that serve many requests over one connection save significant latency and resources. HTTP/1.0 required an explicit `Connection: keep-alive`, but from HTTP/1.1 persistent connections are the default and you send `Connection: close` to end one. The Keep-Alive header is supplementary info telling the peer this persistent connection's parameters (idle timeout, max requests).
`timeout` hints the minimum seconds to hold an idle connection, and `max` is the maximum requests to serve on it. The values are hints, not mandates, and either side may close the connection once its condition is met. When client, server, and reverse-proxy keep-alive timeouts disagree, one side may send a request on a connection the other already closed, causing a race — so aligning the values matters.
Both Keep-Alive and Connection are hop-by-hop headers, forbidden in HTTP/2 and HTTP/3. Those protocols multiplex many streams over one connection, so connection reuse is built into the protocol itself and needs no separate header. Thus Keep-Alive is HTTP/1.x only.
Keep-Alive: timeout=<seconds>[, max=<requests>]e.g. Keep-Alive: timeout=5, max=1000
timeout=<seconds> | A hint of the minimum seconds to keep an idle connection open; after that idle time it may be closed. |
max=<requests> | The maximum number of requests to serve on this connection; when reached, the connection closes. |