← Back to headers
HTTP Header
Connection
GeneralControls whether the network connection stays open after the current transaction.
HTTP header reference, syntax, examples, and developer usage.
What is the Connection header?
The Connection HTTP header is used to transmit metadata between a client and server as part of HTTP requests or responses.
HTTP headers define how content should be interpreted, cached, authenticated, secured, or processed by browsers and APIs.
Direction
This header may appear in both HTTP requests and responses.
Syntax
Connection: keep-alive | close
Example
Connection: keep-alive
Common use cases
- Keeping TCP connections open for multiple requests
- Explicitly closing a connection after a response
- Managing connection lifecycle in HTTP/1.1
Common mistakes
- Using the header in the wrong request or response context
- Sending invalid header values
- Incorrect header syntax
- Assuming the header automatically changes server behaviour
Practical developer insight
In HTTP/1.1, connections are persistent by default so Connection: keep-alive is rarely needed explicitly. Connection: close is more commonly used when you want to signal the end of a session. Connection is a hop-by-hop header, meaning intermediaries must not forward it. It has no effect in HTTP/2 or HTTP/3.