From d8ff55052866645af2ff6b9352c012e78ba1678a Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 6 Sep 2017 17:22:42 -0400 Subject: [PATCH] http2: store headersSent after stream destroyed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store headersSent directly on response state after finish event is triggered, so that users can always access it. PR-URL: https://github.com/nodejs/node/pull/15232 Fixes: https://github.com/nodejs/node/issues/15226 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Benjamin Gruenbaum Reviewed-By: Luigi Pinca Reviewed-By: Tobias Nießen --- lib/internal/http2/compat.js | 3 ++- test/parallel/test-http2-compat-serverresponse-headers.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index c959824d820f09..fa565e9bd67386 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -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() { @@ -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'); diff --git a/test/parallel/test-http2-compat-serverresponse-headers.js b/test/parallel/test-http2-compat-serverresponse-headers.js index 717d8b00352546..b2285f9d2aabfc 100644 --- a/test/parallel/test-http2-compat-serverresponse-headers.js +++ b/test/parallel/test-http2-compat-serverresponse-headers.js @@ -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();