fix: support Connection header with connection-specific header names per RFC 7230#4775
Open
fix: support Connection header with connection-specific header names per RFC 7230#4775
Conversation
…per RFC 7230 Per RFC 7230 Section 6.1, the Connection header can contain a comma-separated list of connection option tokens (header names) that should be removed by proxies before forwarding the message. Previously, undici only allowed 'close' or 'keep-alive' as Connection header values. This change allows any valid HTTP token as a connection option, enabling RFC-compliant requests like: Connection: X-Custom-Header Connection: close, X-Custom-Header Fixes: #4774 Signed-off-by: Matteo Collina <hello@matteocollina.com>
metcoder95
reviewed
Jan 27, 2026
lib/core/request.js
Outdated
| } | ||
|
|
||
| if (value === 'close') { | ||
| const tokens = value.split(',').map(t => t.trim().toLowerCase()) |
Member
There was a problem hiding this comment.
We are iterating over them twice, can we do it at one pass?
Contributor
There was a problem hiding this comment.
You could actually lowercase before split.
Member
Author
There was a problem hiding this comment.
Done! Refactored to lowercase before split and combined validation + close-check in a single loop.
- Lowercase before split as suggested - Combine validation and close-check in single loop Signed-off-by: Matteo Collina <hello@matteocollina.com>
The previous test used 'asd' as an invalid connection header value, but 'asd' is a valid HTTP token per RFC 7230. Updated to use a truly invalid value (token with spaces) instead. Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4775 +/- ##
=======================================
Coverage 93.25% 93.25%
=======================================
Files 109 109
Lines 34024 34032 +8
=======================================
+ Hits 31728 31736 +8
Misses 2296 2296 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
metcoder95
approved these changes
Jan 29, 2026
Signed-off-by: Matteo Collina <hello@matteocollina.com> # Conflicts: # test/request.js
Member
Author
|
@metcoder95 ping |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
closeorkeep-alivewere accepted, now any valid HTTP token is allowedrequest.reset = trueifcloseis present in the token listTest plan
closeandkeep-alivevaluesFixes #4774