diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index ddc017a144cfbe..4795e59581d993 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -480,6 +480,7 @@ class Http2ServerResponse extends Stream { stream[kProxySocket] = null; stream[kResponse] = this; this.writable = true; + this.req = stream[kRequest]; stream.on('drain', onStreamDrain); stream.on('aborted', onStreamAbortedResponse); stream.on('close', onStreamCloseResponse); @@ -529,10 +530,6 @@ class Http2ServerResponse extends Stream { return this[kStream].headersSent; } - get req() { - return this[kStream][kRequest]; - } - get sendDate() { return this[kState].sendDate; } diff --git a/test/parallel/test-http2-compat-serverresponse.js b/test/parallel/test-http2-compat-serverresponse.js index 379677a68f81e1..fbde58693b05a7 100644 --- a/test/parallel/test-http2-compat-serverresponse.js +++ b/test/parallel/test-http2-compat-serverresponse.js @@ -14,6 +14,9 @@ server.listen(0, common.mustCall(function() { server.once('request', common.mustCall(function(request, response) { assert.strictEqual(response.req, request); + // Verify that writing to response.req is allowed. + response.req = null; + response.on('finish', common.mustCall(function() { process.nextTick(() => { server.close();