-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: http server multi same-named headers support #6865
lib: http server multi same-named headers support #6865
Conversation
Let http server support response multiple same-named header as RFC2612 defined, this feature is also used in http/2.0 "server push" feature. Fix nodejs#3591
On FreeBSD, I got something like this on the branch for this PR by running test:
|
These test failures reflect the expectation that when sending multiple, identically named HTTP headers, the last one takes precedence. They would need to be changed in this PR, and, ideally, new ones would be added that test the new behaviour. /cc @nodejs/http |
Thank you @addaleax ! |
e6ecde7
to
9e31d64
Compare
I updated the test and now it passed, but I'm not sure if I did it right, waiting for review now, I'm new to this, please feel free to correct me, many thanks. |
@@ -103,7 +103,7 @@ function nextTest() { | |||
break; | |||
|
|||
case 'writeHead': | |||
assert.equal(response.headers['x-foo'], 'bar'); | |||
assert.equal(response.headers['x-foo'], 'keyboard cat'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn’t the output here be keyboard cat, bar
? For incoming http messages node glues the returned header values together with ', '
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmmm ... I'll take a look at writeHead
function, thanks.
I'm not quite understand what this PR is looking to achieve. The http implementation already support multiple same-named headers. There are a specific subset of headers that may only be sent once (like Content-Length) but for the others it's certainly already possible to send multiple headers with the same name. |
Uh, yeah, @jasnell’s right. I think that original issue linked above can be closed then? |
For outgoing responses, I've never had an issue sending multiple same-named headers as different header lines in the underlying response. Express.js even has an API |
@jasnell @dougwilson sorry that since that issue #3591 has no any response for a while, so I thought it's still a problem, I should be more careful, that's my fault. Actually, @dougwilson you are right, |
This PR does seem to break additional functionality, for example, It also seems to have the edge case of the following not working: res.setHeader('X-Log', 'test')
res.setHeader('X-Log', 'test2')
res.setHeader('X-Log0', 'test3')
assert.equal(res.getHeader('X-Log0'), 'test3') // fails with this PR Though of course the PR is currently very rough, as it doesn't look like the current accesses to |
@dougwilson thanks for your review, if this function/feature can be accepted, I'll like to fix the problems you mentioned 😄 |
While I definitely appreciate the contribution, I certainly doubt that this PR would land. |
@jasnell it's okay if it won't be accepted, no mind. |
Given the responses, closing this. Thank you for the contribution tho! |
This is my first PR to nodejs, hope didn't do anything stupid or funny ... Thanks.
Checklist
Affected core subsystem(s)
lib/_http_outgoing.js
Description of change
Let http server support response multiple same-named header as RFC2612
defined, this feature is also used in http/2.0 "server push" feature.
Fix #3591