-
-
Notifications
You must be signed in to change notification settings - Fork 693
Description
Summary
When using undici to make HTTP requests, attempting to send a Connection header with a value that lists other header names (per RFC 7230 Section 6.1) results in an InvalidArgumentError: invalid connection header.
Background
RFC 7230 Section 6.1 specifies that the Connection header field can contain a comma-separated list of connection-option tokens, which correspond to header field names that should be removed by the first proxy or gateway that receives the message.
The "Connection" header field allows the sender to indicate desired control options for the current connection. In order to avoid confusing downstream recipients, a proxy or gateway MUST remove or replace any received connection options before forwarding the message.
Example from the RFC:
Connection: close
Connection: keep-alive, Upgrade
Connection: X-Custom-Header
Current Behavior
const { request } = require('undici');
await request('http://example.com', {
headers: {
'X-Custom-Header': 'some-value',
'Connection': 'X-Custom-Header' // RFC-compliant header value
}
});
// Throws: InvalidArgumentError: invalid connection headerExpected Behavior
Undici should allow Connection header values that contain comma-separated lists of header names, per RFC 7230 Section 6.1.
Use Case
This is relevant for proxy implementations where a client sends a Connection header listing custom headers to strip. While undici/proxies should strip these headers before forwarding (as we now do in @fastify/reply-from), the current undici behavior prevents clients from sending RFC-compliant requests in the first place.
References
- RFC 7230 Section 6.1 - Connection
- Related fix in @fastify/reply-from: Strip headers listed in Connection header per RFC 7230 Section 6.1 fastify/fastify-reply-from#449