Skip to content

Commit b5d5dd7

Browse files
committed
Revert "http2: avoid copying the options in respond()"
This reverts commit 3329647. PR-URL: #64663 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent fa1a5f3 commit b5d5dd7

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

‎lib/internal/http2/core.js‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,35 +2654,31 @@ function prepareResponseHeaders(stream, headersParam, options) {
26542654
functionprepareResponseHeadersObject(oldHeaders,options){
26552655
assertIsObject(oldHeaders,'headers',['Object','Array']);
26562656
constheaders={__proto__: null};
2657-
letstatusCode;
2658-
lethasDate=false;
26592657

26602658
if(oldHeaders!==null&&oldHeaders!==undefined){
26612659
// This loop is here for performance reason. Do not change.
2662-
// The :status and date fields are picked up while copying so they do
2663-
// not have to be looked up again on the null-prototype copy.
26642660
for(constkeyinoldHeaders){
26652661
if(ObjectHasOwn(oldHeaders,key)){
2666-
constvalue=oldHeaders[key];
2667-
headers[key]=value;
2668-
if(key===HTTP2_HEADER_STATUS)
2669-
statusCode=value;
2670-
elseif(key===HTTP2_HEADER_DATE)
2671-
hasDate=value!=null;
2662+
headers[key]=oldHeaders[key];
26722663
}
26732664
}
26742665
headers[kSensitiveHeaders]=oldHeaders[kSensitiveHeaders];
26752666
}
26762667

2677-
statusCode=headers[HTTP2_HEADER_STATUS]=statusCode|0||HTTP_STATUS_OK;
2668+
conststatusCode=
2669+
headers[HTTP2_HEADER_STATUS]=
2670+
headers[HTTP2_HEADER_STATUS]|0||HTTP_STATUS_OK;
26782671

2679-
if(!hasDate&&(options.sendDate==null||options.sendDate)){
2680-
headers[HTTP2_HEADER_DATE]=utcDate();
2672+
if(options.sendDate==null||options.sendDate){
2673+
headers[HTTP2_HEADER_DATE]??=utcDate();
26812674
}
26822675

26832676
validatePreparedResponseHeaders(headers,statusCode);
26842677

2685-
return{ headers, statusCode };
2678+
return{
2679+
headers,
2680+
statusCode: headers[HTTP2_HEADER_STATUS],
2681+
};
26862682
}
26872683

26882684
functionprepareResponseHeadersArray(headers,options){
@@ -3051,17 +3047,15 @@ class ServerHttp2Stream extends Http2Stream {
30513047
conststate=this[kState];
30523048

30533049
assertIsObject(options,'options');
3054-
// The options are only read, never mutated, so the user-provided object
3055-
// can be used directly instead of copying it.
3056-
options??=kEmptyObject;
3050+
options={ ...options};
30573051

30583052
debugStreamObj(this,'initiating response');
30593053
this[kUpdateTimer]();
30603054

3061-
constendStream=!!options.endStream;
3055+
options.endStream=!!options.endStream;
30623056

30633057
letstreamOptions=0;
3064-
if(endStream)
3058+
if(options.endStream)
30653059
streamOptions|=STREAM_OPTION_EMPTY_PAYLOAD;
30663060

30673061
if(options.waitForTrailers){
@@ -3079,11 +3073,12 @@ class ServerHttp2Stream extends Http2Stream {
30793073

30803074
// Close the writable side if the endStream option is set or status
30813075
// is one of known codes with no payload, or it's a head request
3082-
if(endStream||
3076+
if(!!options.endStream||
30833077
statusCode===HTTP_STATUS_NO_CONTENT||
30843078
statusCode===HTTP_STATUS_RESET_CONTENT||
30853079
statusCode===HTTP_STATUS_NOT_MODIFIED||
30863080
this.headRequest===true){
3081+
options.endStream=true;
30873082
this.end();
30883083
}
30893084

0 commit comments

Comments
 (0)