Skip to content

Commit

Permalink
http2: make compat finished match http/1
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ronag authored and codebytere committed Feb 27, 2020
1 parent bbb6cc7 commit 9079bb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 4 additions & 7 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,8 @@ class Http2ServerResponse extends Stream {
}

get finished() {
const stream = this[kStream];
return stream.destroyed ||
stream._writableState.ended ||
this[kState].closed;
const state = this[kState];
return state.ending;
}

get socket() {
Expand Down Expand Up @@ -700,12 +698,11 @@ class Http2ServerResponse extends Stream {
if (chunk !== null && chunk !== undefined)
this.write(chunk, encoding);

const isFinished = this.finished;
state.headRequest = stream.headRequest;
state.ending = true;

if (typeof cb === 'function') {
if (isFinished)
if (stream.writableEnded)
this.once('finish', cb);
else
stream.once('finish', cb);
Expand All @@ -714,7 +711,7 @@ class Http2ServerResponse extends Stream {
if (!stream.headersSent)
this.writeHead(this[kState].statusCode);

if (isFinished)
if (this[kState].closed || stream.destroyed)
onStreamCloseResponse.call(stream);
else
stream.end();
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-compat-serverresponse-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ const {
// Http2ServerResponse.end is necessary on HEAD requests in compat
// for http1 compatibility
const server = createServer(mustCall((request, response) => {
strictEqual(response.finished, true);
strictEqual(response.writableEnded, false);
strictEqual(response.finished, false);
response.writeHead(HTTP_STATUS_OK, { foo: 'bar' });
strictEqual(response.finished, false);
response.end('data', mustCall());
strictEqual(response.writableEnded, true);
strictEqual(response.finished, true);
}));
server.listen(0, mustCall(() => {
const { port } = server.address();
Expand Down

0 comments on commit 9079bb4

Please sign in to comment.