Skip to content

Support sending Connection header with connection-specific header names per RFC 7230 #4774

@mcollina

Description

@mcollina

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 header

Expected 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions