mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01: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
f7ca0ae765
commit
1f2c9f82b7
|
|
@ -673,20 +673,22 @@ OutgoingMessage.prototype.setHeaders = function setHeaders(headers) {
|
||||||
// We also cannot safely split by comma.
|
// We also cannot safely split by comma.
|
||||||
// To avoid setHeader overwriting the previous value we push
|
// To avoid setHeader overwriting the previous value we push
|
||||||
// set-cookie values in array and set them all at once.
|
// set-cookie values in array and set them all at once.
|
||||||
const cookies = [];
|
let cookies = null;
|
||||||
|
|
||||||
for (const { 0: key, 1: value } of headers) {
|
for (const { 0: key, 1: value } of headers) {
|
||||||
if (key === 'set-cookie') {
|
if (key === 'set-cookie') {
|
||||||
if (ArrayIsArray(value)) {
|
if (ArrayIsArray(value)) {
|
||||||
|
cookies ??= [];
|
||||||
cookies.push(...value);
|
cookies.push(...value);
|
||||||
} else {
|
} else {
|
||||||
|
cookies ??= [];
|
||||||
cookies.push(value);
|
cookies.push(value);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.setHeader(key, value);
|
this.setHeader(key, value);
|
||||||
}
|
}
|
||||||
if (cookies.length) {
|
if (cookies != null) {
|
||||||
this.setHeader('set-cookie', cookies);
|
this.setHeader('set-cookie', cookies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user