From 7551a8be477f87554e74ec78ee585f3afd213599 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 3f86262e737a3f..82cbfcc5132f35 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());