Skip to content

Commit 95644a4

Browse files
ronagaduh95
authored andcommitted
http: lazy allocate cookies array
PR-URL: #59734 Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 425a187 commit 95644a4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

‎lib/_http_outgoing.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,20 +673,22 @@ OutgoingMessage.prototype.setHeaders = function setHeaders(headers){
673673
// We also cannot safely split by comma.
674674
// To avoid setHeader overwriting the previous value we push
675675
// set-cookie values in array and set them all at once.
676-
constcookies=[];
676+
letcookies=null;
677677

678678
for(const{0: key,1: value}ofheaders){
679679
if(key==='set-cookie'){
680680
if(ArrayIsArray(value)){
681+
cookies??=[];
681682
cookies.push(...value);
682683
}else{
684+
cookies??=[];
683685
cookies.push(value);
684686
}
685687
continue;
686688
}
687689
this.setHeader(key,value);
688690
}
689-
if(cookies.length){
691+
if(cookies!=null){
690692
this.setHeader('set-cookie',cookies);
691693
}
692694

0 commit comments

Comments
(0)