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.

Fixes: #15226
  • Loading branch information
apapirovski committed Sep 7, 2017
1 parent 4477155 commit a5d6a6f
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 @@ -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

0 comments on commit a5d6a6f

Please sign in to comment.