GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: emit timeout on compat request and response · nodejs/node@348cde0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/http2
    • compat.js
  • test/parallel
    • test-http2-compat-serverrequest-settimeout.js
    • test-http2-compat-serverresponse-settimeout.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http2/compat.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ function onStreamCloseRequest() {
229229
req.emit('close');
230230
}
231231

232+
function onStreamTimeout(kind) {
233+
return function onStreamTimeout() {
234+
const obj = this[kind];
235+
obj.emit('timeout');
236+
};
237+
}
238+
232239
class Http2ServerRequest extends Readable {
233240
constructor(stream, headers, options, rawHeaders) {
234241
super(options);
@@ -251,6 +258,7 @@ class Http2ServerRequest extends Readable {
251258
stream.on('error', onStreamError);
252259
stream.on('aborted', onStreamAbortedRequest);
253260
stream.on('close', onStreamCloseRequest);
261+
stream.on('timeout', onStreamTimeout(kRequest));
254262
this.on('pause', onRequestPause);
255263
this.on('resume', onRequestResume);
256264
}
@@ -403,6 +411,7 @@ class Http2ServerResponse extends Stream {
403411
stream.on('aborted', onStreamAbortedResponse);
404412
stream.on('close', onStreamCloseResponse);
405413
stream.on('wantTrailers', onStreamTrailersReady);
414+
stream.on('timeout', onStreamTimeout(kResponse));
406415
}
407416

408417
// User land modules such as finalhandler just check truthiness of this
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverrequest-settimeout.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const http2 = require('http2');
88

9-
const msecs = common.platformTimeout(1);
9+
// Set the timeout to 10ms since ending the response stream resets the timer.
10+
const msecs = common.platformTimeout(10);
1011
const server = http2.createServer();
1112

1213
server.on('request', (req, res) => {
1314
req.setTimeout(msecs, common.mustCall(() => {
1415
res.end();
1516
}));
17+
res.on('timeout', common.mustCall());
1618
res.on('finish', common.mustCall(() => {
1719
req.setTimeout(msecs, common.mustNotCall());
1820
process.nextTick(() => {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http2-compat-serverresponse-settimeout.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ if (!common.hasCrypto)
66
const assert = require('assert');
77
const http2 = require('http2');
88

9-
const msecs = common.platformTimeout(1);
9+
// Set the timeout to 10ms since ending the response stream resets the timer.
10+
const msecs = common.platformTimeout(10);
1011
const server = http2.createServer();
1112

1213
server.on('request', (req, res) => {
1314
res.setTimeout(msecs, common.mustCall(() => {
1415
res.end();
1516
}));
17+
res.on('timeout', common.mustCall());
1618
res.on('finish', common.mustCall(() => {
1719
res.setTimeout(msecs, common.mustNotCall());
1820
process.nextTick(() => {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.