From e3fd2f5a4866a30108978047e09c15af509b1b4a Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Sun, 21 Jun 2020 00:49:56 +0530 Subject: [PATCH] http2: return this for Http2ServerRequest#setTimeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: https://github.com/nodejs/node/issues/33993 PR-URL: https://github.com/nodejs/node/pull/33994 Reviewed-By: Anna Henningsen Reviewed-By: Luigi Pinca Reviewed-By: Zeyu Yang Reviewed-By: James M Snell Reviewed-By: Gerhard Stöbich --- lib/internal/http2/compat.js | 6 +++--- test/parallel/test-http2-compat-serverrequest-settimeout.js | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 00f5ecfce24543..085ae11b9e5491 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -405,9 +405,9 @@ class Http2ServerRequest extends Readable { } setTimeout(msecs, callback) { - if (this[kState].closed) - return; - this[kStream].setTimeout(msecs, callback); + if (!this[kState].closed) + this[kStream].setTimeout(msecs, callback); + return this; } } diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 4b7a629cf55fde..44abf29cafb9d9 100644 --- a/test/parallel/test-http2-compat-serverrequest-settimeout.js +++ b/test/parallel/test-http2-compat-serverrequest-settimeout.js @@ -3,15 +3,17 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const http2 = require('http2'); const msecs = common.platformTimeout(1); const server = http2.createServer(); server.on('request', (req, res) => { - req.setTimeout(msecs, common.mustCall(() => { + const request = req.setTimeout(msecs, common.mustCall(() => { res.end(); })); + assert.strictEqual(request, req); req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall());