🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Connection

HTTP Header

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.

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 headerYes

Syntax

http
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:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. 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).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. 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.