From c737df64fe0a2d4775be13209ff49d5b390736a1 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Wed, 10 Mar 2021 20:41:35 -0500 Subject: [PATCH] http2: make res.req a normal property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The change in https://github.com/nodejs/node/pull/36505 broke userland code that already wrote to res.req. This commit updates the res.req property in the http2 compat layer to be a normal property. PR-URL: https://github.com/nodejs/node/pull/37706 Fixes: https://github.com/nodejs/node/issues/37705 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Darshan Sen Reviewed-By: Robert Nagy Reviewed-By: Mary Marchini Reviewed-By: Gerhard Stöbich Reviewed-By: Michaël Zasso --- lib/internal/http2/compat.js | 5 +---- test/parallel/test-http2-compat-serverresponse.js | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) 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();