diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 33f636f69bf54c..40276d87234865 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -241,6 +241,13 @@ function onStreamCloseRequest() { req.emit('close'); } +function onStreamTimeout(kind) { + return function onStreamTimeout() { + const obj = this[kind]; + obj.emit('timeout'); + }; +} + class Http2ServerRequest extends Readable { constructor(stream, headers, options, rawHeaders) { super(options); @@ -263,6 +270,7 @@ class Http2ServerRequest extends Readable { stream.on('error', onStreamError); stream.on('aborted', onStreamAbortedRequest); stream.on('close', onStreamCloseRequest); + stream.on('timeout', onStreamTimeout(kRequest)); this.on('pause', onRequestPause); this.on('resume', onRequestResume); } @@ -416,6 +424,7 @@ class Http2ServerResponse extends Stream { stream.on('aborted', onStreamAbortedResponse); stream.on('close', onStreamCloseResponse); stream.on('wantTrailers', onStreamTrailersReady); + stream.on('timeout', onStreamTimeout(kResponse)); } // User land modules such as finalhandler just check truthiness of this diff --git a/test/parallel/test-http2-compat-serverrequest-settimeout.js b/test/parallel/test-http2-compat-serverrequest-settimeout.js index 81184d70752563..4b7a629cf55fde 100644 --- a/test/parallel/test-http2-compat-serverrequest-settimeout.js +++ b/test/parallel/test-http2-compat-serverrequest-settimeout.js @@ -12,6 +12,7 @@ server.on('request', (req, res) => { req.setTimeout(msecs, common.mustCall(() => { res.end(); })); + req.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { req.setTimeout(msecs, common.mustNotCall()); process.nextTick(() => { diff --git a/test/parallel/test-http2-compat-serverresponse-settimeout.js b/test/parallel/test-http2-compat-serverresponse-settimeout.js index 220a84a754d651..e24621ad097f3f 100644 --- a/test/parallel/test-http2-compat-serverresponse-settimeout.js +++ b/test/parallel/test-http2-compat-serverresponse-settimeout.js @@ -12,6 +12,7 @@ server.on('request', (req, res) => { res.setTimeout(msecs, common.mustCall(() => { res.end(); })); + res.on('timeout', common.mustCall()); res.on('finish', common.mustCall(() => { res.setTimeout(msecs, common.mustNotCall()); process.nextTick(() => {