Connection
The HTTP Connection header dictates whether the network connection remains open after completing the current transaction. If the value sent is keep-alive, the connection is persistent and is not closed, enabling subsequent requests to the same server over the same connection.
Note: Connection-specific header fields such as Connection and Keep-Alive are not permitted in HTTP/2 and HTTP/3. Browsers like Chrome and Firefox ignore these headers in HTTP/2 responses, while Safari adheres to the HTTP/2 specifications and will not load responses containing them.
All hop-by-hop headers, including the standard hop-by-hop headers (Keep-Alive, Transfer-Encoding, TE, Connection, Trailer, Upgrade, Proxy-Authorization, and Proxy-Authenticate) must be specified in the Connection header, so that the initial proxy understands that it needs to process them and not forward the headers further. The default value for Connection shifted from HTTP/1.0 to HTTP/1.1. Hence, browsers often explicitly send Connection: keep-alive for backward compatibility, even though this is the default in HTTP/1.1.
| Header type | Request header, Response header |
|---|---|
| Forbidden request header | Yes |
Syntax
Connection: keep-alive
Connection: close
Directives
close
Indicates that either the client or the server intends to close the connection. This directive is the default for HTTP/1.0 requests.
any comma-separated list of HTTP headers (usually keep-alive only)
Indicates that the client prefers to keep the connection open. Keeping the connection alive is the default behavior in HTTP/1.1 requests. The headers listed specify which headers should be removed by the first non-transparent proxy or cache between the client and the server. These headers define the connection setting between the emitter and the first entity, not the final destination node.
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Connection header. This can help you control how connections are managed between the client and server, which is useful for debugging issues related to connection persistence or closing. Steps to Modify the Connection Header:
- Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
- Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
- Add a new header modification:
- Under “Action”, select “Add” or “Override”.
- In the “Header Name” field, enter Connection.
- In the “Header Value” field, enter your desired connection behavior (e.g., keep-alive or close).
- Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/\*).
- Save the rule.
Once set up, Requestly will modify the Connection header in all matching requests, allowing you to test how your server handles connection persistence or termination. Modifying the Connection header is helpful when you want to test how your application manages HTTP connections, such as keeping them open for better performance or closing them to release resources faster.
Set headers visually: intercept and modify HTTP headers without touching your code using Requestly.
Download Free →