Connection
The Connection header lists hop-by-hop headers in an HTTP/1 message, and other desired control options for the next node downstream.
This header is typically handled entirely by HTTP libraries and servers on behalf of the application, see section below on implementations.
All connection options are case-insensitive.
Usage in user agents
Clients (including intermediaries) must list any connection headers (besides Connection itself) in the Connection header.
Clients that do not support persistent connections must send the close
token in every request.
Clients that
Clients that receive either Connection: close
or an HTTP/1.0 response without Connection: keep-alive
from the upstream node may re-try any pipelined requests .
Usage in intermediaries
Intermediaries forwarding the message to another node must only forward end-to-end headers, skipping connection headers, either the Connection header, or any header whose name appears in it.
Intermediate clients add their own Connection header as necessary.
For workarounds for historical problems, a proxy server must not maintain a keep-alive connection with an HTTP/1.0 client.
Usage in origin servers
Servers that do not support persistent connections must send the close
token in every response (non-1xx).
Servers responding to a request with Connection: close
should also respond with close
.
Values
Name of a header
The value of the Connection
header is a list of header names that describe the state of the incoming connection, and as such do not make sense to forward. Any headers listed by this header MUST NOT be forwarded.
Special token
Unknown tokens can be ignored. If knowledge of a token is essential, the client or server will use a version of HTTP that specifies the behavior.
Some names are reserved as special values. The close
token indicates the connection will be closed after the current message (request/response) is written out. Servers that see "close" in a request should close the connection after finishing the response.
The keep-alive
token is used as a special value by HTTP/1.0 clients. See RFC7230 for implementation details.
Overview table
- Name
- Connection
- Description
- Lists hop-by-hop headers that must be consumed by the downstream node.
- Direction
- Both
- Specification
- RFC 7230: HTTP/1.1 Message Syntax and Routing ยง6.1. Connection
Special values
Any values for Connection
that do not appear as the name of one of the message headers is a control option for the current connection. Unknown values may be ignored.
Connection: close
See closing client connections for usage in responses.
Connection: keep-alive
The keep-alive
token is limited to use in HTTP/1.0 connections where perstistent connections are not the default.
HTTP/1.0 defines a Keep-Alive
header, but Connection may specify keep-alive
as a token without using the header.
List of connection headers
In addition to Connection
itself, the following headers are known to be connection headers:
Syntax
Connection = 1#connection-option
connection-option = token
Connection options are case-insensitive. For clarity, connection options are typically written in lowercase, and header names are typically written in title case.
Example
Connection: close
Implementation status
Node.js
Node.js emits the header correctly, but does not segregate connection headers from end-to-end headers when reading messages. If writing an application that will forward the message, it must be programmed to omit the Connection
header and any headers whose names appear within it, before forwarding.