Skip to content

Commit

Permalink
http2: store headersSent after stream destroyed
Browse files Browse the repository at this point in the history
Store headersSent directly on response state after finish event
is triggered, so that users can always access it.

PR-URL: #15232
Fixes: #15226
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
apapirovski authored and MylesBorins committed Sep 12, 2017
1 parent 71f90c6 commit d8ff550
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class Http2ServerResponse extends Stream {

get headersSent() {
const stream = this[kStream];
return stream.headersSent;
return stream !== undefined ? stream.headersSent : this[kState].headersSent;
}

get sendDate() {
Expand Down Expand Up @@ -542,6 +542,7 @@ class Http2ServerResponse extends Stream {
if (code !== undefined)
state.closedCode = code;
state.closed = true;
state.headersSent = this[kStream].headersSent;
this.end();
this[kStream] = undefined;
this.emit('finish');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-http2-compat-serverresponse-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ server.listen(0, common.mustCall(function() {

response.on('finish', common.mustCall(function() {
assert.strictEqual(response.code, h2.constants.NGHTTP2_NO_ERROR);
assert.strictEqual(response.headersSent, true);
server.close();
}));
response.end();
Expand Down

0 comments on commit d8ff550

Please sign in to comment.