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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
rexagod authored and addaleax committed Jun 25, 2020

Verified

This commit was signed with the committer’s verified signature.
addaleax Anna Henningsen
1 parent 3646872 commit ac80fed
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
@@ -411,9 +411,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;
}
}

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

0 comments on commit ac80fed

Please sign in to comment.