mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
http: lazy allocate cookies array
PR-URL: https://github.com/nodejs/node/pull/59734 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
425a1879b1
commit
95644a432c
@ -673,20 +673,22 @@ OutgoingMessage.prototype.setHeaders = function setHeaders(headers) {
|
||||
// We also cannot safely split by comma.
|
||||
// To avoid setHeader overwriting the previous value we push
|
||||
// set-cookie values in array and set them all at once.
|
||||
const cookies = [];
|
||||
let cookies = null;
|
||||
|
||||
for (const { 0: key, 1: value } of headers) {
|
||||
if (key === 'set-cookie') {
|
||||
if (ArrayIsArray(value)) {
|
||||
cookies ??= [];
|
||||
cookies.push(...value);
|
||||
} else {
|
||||
cookies ??= [];
|
||||
cookies.push(value);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
this.setHeader(key, value);
|
||||
}
|
||||
if (cookies.length) {
|
||||
if (cookies != null) {
|
||||
this.setHeader('set-cookie', cookies);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user