Skip to content

Commit 76a0ba6

Browse files
ronagcodebytere
authored andcommitted
http2: make compat finished match http/1
finished should true directly after end(). PR-URL: #24347 Refs: #24743 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7092563 commit 76a0ba6

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

‎lib/internal/http2/compat.js‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,8 @@ class Http2ServerResponse extends Stream{
471471
}
472472

473473
getfinished(){
474-
conststream=this[kStream];
475-
returnstream.destroyed||
476-
stream._writableState.ended||
477-
this[kState].closed;
474+
conststate=this[kState];
475+
returnstate.ending;
478476
}
479477

480478
getsocket(){
@@ -700,12 +698,11 @@ class Http2ServerResponse extends Stream{
700698
if(chunk!==null&&chunk!==undefined)
701699
this.write(chunk,encoding);
702700

703-
constisFinished=this.finished;
704701
state.headRequest=stream.headRequest;
705702
state.ending=true;
706703

707704
if(typeofcb==='function'){
708-
if(isFinished)
705+
if(stream.writableEnded)
709706
this.once('finish',cb);
710707
else
711708
stream.once('finish',cb);
@@ -714,7 +711,7 @@ class Http2ServerResponse extends Stream{
714711
if(!stream.headersSent)
715712
this.writeHead(this[kState].statusCode);
716713

717-
if(isFinished)
714+
if(this[kState].closed||stream.destroyed)
718715
onStreamCloseResponse.call(stream);
719716
else
720717
stream.end();

‎test/parallel/test-http2-compat-serverresponse-end.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ const{
149149
// Http2ServerResponse.end is necessary on HEAD requests in compat
150150
// for http1 compatibility
151151
constserver=createServer(mustCall((request,response)=>{
152-
strictEqual(response.finished,true);
153152
strictEqual(response.writableEnded,false);
153+
strictEqual(response.finished,false);
154154
response.writeHead(HTTP_STATUS_OK,{foo: 'bar'});
155+
strictEqual(response.finished,false);
155156
response.end('data',mustCall());
156157
strictEqual(response.writableEnded,true);
158+
strictEqual(response.finished,true);
157159
}));
158160
server.listen(0,mustCall(()=>{
159161
const{ port }=server.address();

0 commit comments

Comments
(0)