Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
http2: store headersSent after stream destroyed
Store headersSent directly on response state after finish event
is triggered, so that users can always access it.

Fixes: #15226
  • Loading branch information
apapirovski committed Sep 7, 2017
commit a5d6a6fc09c7d8064569dfe7f0e37ae224312cff
3 changes: 2 additions & 1 deletion lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,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 @@ -526,6 +526,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