Skip to content

Commit

Permalink
http2: return this for Http2ServerRequest#setTimeout
Browse files Browse the repository at this point in the history
Fixes: #33993

PR-URL: #33994
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
rexagod authored and codebytere committed Jun 30, 2020
1 parent 63c9e16 commit e3060dd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-compat-serverrequest-settimeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e3060dd

Please sign in to comment.