Connection

The HTTP Connection header controls whether the network connection stays open after the current transaction completes.

Usage

The Connection header is a hop-by-hop header in HTTP/1.1 used to manage the lifecycle of the underlying TCP connection. A client or server includes this header to signal whether the connection persists for additional requests or closes after the current exchange.

In HTTP/1.1, persistent connections are the default behavior. Sending Connection: keep-alive is technically redundant but remains common in practice. The Keep-Alive header works alongside the Connection header to set timeout and request limits on persistent connections.

The Connection header also serves a second role: listing hop-by-hop header field names present in the message. Intermediaries (proxies, gateways) remove any header listed in the Connection value before forwarding the message to the next hop.

Note

The Connection header is forbidden in HTTP/2 and HTTP/3. These protocols manage connection lifecycle through their own framing layers. Proxies converting between HTTP/1.1 and HTTP/2 strip this header automatically.

Directives

keep-alive

The keep-alive directive signals the sender wants the connection to remain open for subsequent requests. This is the default in HTTP/1.1. When present, the Keep-Alive header provides parameters like idle timeout and maximum request count.

close

The close directive tells the other party to close the connection after completing the current request-response pair. In HTTP/1.0, closing after each transaction was the default behavior.

Example

A client sends a request with an explicit keep-alive directive. This tells the server to hold the TCP connection open after delivering the response.

GET /api/status HTTP/1.1
Host: api.example.re
Connection: keep-alive

A server signals the connection will close after delivering this response. The client opens a new TCP connection for the next request.

HTTP/1.1 200 OK
Content-Type: application/json
Connection: close

The Connection header also lists hop-by-hop headers. In this example, the proxy strips the X-Debug-Token header before forwarding the message.

GET /resource HTTP/1.1
Host: example.re
Connection: keep-alive, X-Debug-Token
X-Debug-Token: abc123

Takeaway

The Connection header controls TCP connection persistence in HTTP/1.1 and identifies hop-by-hop headers for removal by intermediaries. HTTP/2 and HTTP/3 do not use this header.

See also

Last updated: March 4, 2026