-
Notifications
You must be signed in to change notification settings - Fork 369
Fixed of losing context existing headers in response #1622
Fixed of losing context existing headers in response #1622
Conversation
|
Hi, thanks for the pull-request. Could you expand on the following please?
|
|
Hi, sure! The reproduce steps are located here #1621 Because of Set-Cookie header in the response might be repeated several times. Bug appears when is the request already set an array of the same headers (it's not related only for Set-Cookie header): import express from 'express'
const app = express();
app.get('/', (req, res) => {
// res.cookie('first', 'cookie', { maxAge: 900000, httpOnly: true })
// res.cookie('second', 'cookie', { maxAge: 900000, httpOnly: true })
// res.cookie('third', 'cookie', { maxAge: 900000, httpOnly: true })
// ^^ here the bug, because at this moment we already have in the response an
// array of already set cookies "first=cookie" and "second=cookie"
res.set('X-Powered-By', ['Unit', 'Unit2', 'Unit3']);
res.set('X-Powered-By', ['Unit4', 'Unit5']);
// ^^^ here the bug, the same issue
// in order to set new header with the same name we have to remove prev header
// and set a new one, but because of usage function
res.send('Hello, Express on Unit!')
})
app.listen(8080, () => {
console.log(`Node server is listening on port 8080!`);
});In order to update array of headers with the same name we have to remove previos and add a new one with updated values Now let's change it to the arrow function: It also might be replaced to for cycle instead of arrow function in order to be more similar to code base Also, I've managed how to add tests for that case, may I update the pr? for (let i = 0; i < value.length; i++){
this.headers_len -= Buffer.byteLength(value[i] + "", 'latin1');
}for cycle is faster than foreach And thank you for so quick response! |
|
Thanks for the further explanation.
Sure, you can force push up changes. While you're at it could you expand on the commit message with a summary of what you wrote above? If you're updating the pytests, could you do that as a separate commit? Thanks! |
bcdb544 to
f27762f
Compare
|
Great, thanks! I'll take a look over these. |
|
Just so that I'm 100% with this... It's really any number of duplicate headers, right? 2, 3, 4 etc... |
|
correct. You might reproduce the issue by using the test case from second commit without my changes in the http_server.js file |
7183b92 to
eb1fc49
Compare
|
Tweaked commit messages... |
It fixes losing context in response in cases when there are 2 or more headers with the same name. The prev implementation used to use foreach function which uses local lexical environment and did not find this.headers_len locally, which causes crash of the http server module. It was replaced with a for loop in order to make access for this.headers_len variable and improve performance of calculation. Closes: nginx#1621 Signed-off-by: Andrew Clayton <[email protected]>
Signed-off-by: Andrew Clayton <[email protected]>
eb1fc49 to
a9071e1
Compare
|
Rebased with master |
ac000
left a comment
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.
Thanks @skokalin


It fixes losing context in response in case when here 3 or more Set-Cookie headers.
Closes: #1621
Proposed changes
Bugfix of the existing functionality
Checklist
Before creating a PR, run through this checklist and mark each as complete:
README.mdand/orCHANGELOG.md).Unfortunately I did manage to run any unit tests, because it requires a lot of things to be installed
Would be great if someone could help me with it.