Skip to content

Commit d3ceaa1

Browse files
jasnelltargos
authored andcommitted
http2: emit timeout on compat request and response
Fixes: #20079 PR-URL: #22252 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 3f93782 commit d3ceaa1

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

lib/internal/http2/compat.js

+9
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ function onStreamCloseRequest() {
241241
req.emit('close');
242242
}
243243

244+
function onStreamTimeout(kind) {
245+
return function onStreamTimeout() {
246+
const obj = this[kind];
247+
obj.emit('timeout');
248+
};
249+
}
250+
244251
class Http2ServerRequest extends Readable {
245252
constructor(stream, headers, options, rawHeaders) {
246253
super(options);
@@ -263,6 +270,7 @@ class Http2ServerRequest extends Readable {
263270
stream.on('error', onStreamError);
264271
stream.on('aborted', onStreamAbortedRequest);
265272
stream.on('close', onStreamCloseRequest);
273+
stream.on('timeout', onStreamTimeout(kRequest));
266274
this.on('pause', onRequestPause);
267275
this.on('resume', onRequestResume);
268276
}
@@ -416,6 +424,7 @@ class Http2ServerResponse extends Stream {
416424
stream.on('aborted', onStreamAbortedResponse);
417425
stream.on('close', onStreamCloseResponse);
418426
stream.on('wantTrailers', onStreamTrailersReady);
427+
stream.on('timeout', onStreamTimeout(kResponse));
419428
}
420429

421430
// User land modules such as finalhandler just check truthiness of this

test/parallel/test-http2-compat-serverrequest-settimeout.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ server.on('request', (req, res) => {
1212
req.setTimeout(msecs, common.mustCall(() => {
1313
res.end();
1414
}));
15+
req.on('timeout', common.mustCall());
1516
res.on('finish', common.mustCall(() => {
1617
req.setTimeout(msecs, common.mustNotCall());
1718
process.nextTick(() => {

test/parallel/test-http2-compat-serverresponse-settimeout.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ server.on('request', (req, res) => {
1212
res.setTimeout(msecs, common.mustCall(() => {
1313
res.end();
1414
}));
15+
res.on('timeout', common.mustCall());
1516
res.on('finish', common.mustCall(() => {
1617
res.setTimeout(msecs, common.mustNotCall());
1718
process.nextTick(() => {

0 commit comments

Comments
 (0)