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: add diagnostics channel 'http2.server.stream.created' · nodejs/node@13dbbdc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • diagnostics_channel.md
  • lib/internal/http2
    • core.js
  • test/parallel
    • test-diagnostics-channel-http2-server-stream-created.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/diagnostics_channel.md‎

Copy file name to clipboardExpand all lines: doc/api/diagnostics_channel.md
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,13 @@ Emitted when a stream is received on the client.
12391239
Emitted when a stream is closed on the client. The HTTP/2 error code used when
12401240
closing the stream can be retrieved using the `stream.rstCode` property.
12411241

1242+
`http2.server.stream.created`
1243+
1244+
* `stream` {ServerHttp2Stream}
1245+
* `headers` {HTTP/2 Headers Object}
1246+
1247+
Emitted when a stream is created on the server.
1248+
12421249
#### Modules
12431250

12441251
> Stability: 1 - Experimental
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ const onClientStreamStartChannel = dc.channel('http2.client.stream.start');
190190
const onClientStreamErrorChannel = dc.channel('http2.client.stream.error');
191191
const onClientStreamFinishChannel = dc.channel('http2.client.stream.finish');
192192
const onClientStreamCloseChannel = dc.channel('http2.client.stream.close');
193+
const onServerStreamCreatedChannel = dc.channel('http2.server.stream.created');
193194

194195
let debug = require('internal/util/debuglog').debuglog('http2', (fn) => {
195196
debug = fn;
@@ -367,6 +368,12 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) {
367368
if (type === NGHTTP2_SESSION_SERVER) {
368369
// eslint-disable-next-line no-use-before-define
369370
stream = new ServerHttp2Stream(session, handle, id, {}, obj);
371+
if (onServerStreamCreatedChannel.hasSubscribers) {
372+
onServerStreamCreatedChannel.publish({
373+
stream,
374+
headers: obj,
375+
});
376+
}
370377
if (endOfStream) {
371378
stream.push(null);
372379
}
@@ -2835,6 +2842,13 @@ class ServerHttp2Stream extends Http2Stream {
28352842
stream[kState].flags |= STREAM_FLAGS_HEAD_REQUEST;
28362843

28372844
process.nextTick(callback, null, stream, headers, 0);
2845+
2846+
if (onServerStreamCreatedChannel.hasSubscribers) {
2847+
onServerStreamCreatedChannel.publish({
2848+
stream,
2849+
headers,
2850+
});
2851+
}
28382852
}
28392853

28402854
// Initiate a response on this Http2Stream
Collapse file

‎test/parallel/test-diagnostics-channel-http2-server-stream-created.js‎

Copy file name to clipboard
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
7+
// This test ensures that the built-in HTTP/2 diagnostics channels are reporting
8+
// the diagnostics messages for the 'http2.server.stream.created' channel when
9+
// ServerHttp2Streams are created by both:
10+
// - in response to an incoming 'stream' event from the client
11+
// - the server calling ServerHttp2Stream#pushStream()
12+
13+
const Countdown = require('../common/countdown');
14+
const assert = require('assert');
15+
const dc = require('diagnostics_channel');
16+
const http2 = require('http2');
17+
const { Duplex } = require('stream');
18+
19+
const serverHttp2StreamCreationCount = 2;
20+
21+
dc.subscribe('http2.server.stream.created', common.mustCall(({ stream, headers }) => {
22+
// Since ServerHttp2Stream is not exported from any module, this just checks
23+
// if the stream is an instance of Duplex and the constructor name is
24+
// 'ServerHttp2Stream'.
25+
assert.ok(stream instanceof Duplex);
26+
assert.strictEqual(stream.constructor.name, 'ServerHttp2Stream');
27+
assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object');
28+
}, serverHttp2StreamCreationCount));
29+
30+
const server = http2.createServer();
31+
server.on('stream', common.mustCall((stream) => {
32+
stream.respond();
33+
stream.end();
34+
35+
stream.pushStream({}, common.mustSucceed((pushStream) => {
36+
pushStream.respond();
37+
pushStream.end();
38+
}));
39+
}));
40+
41+
server.listen(0, common.mustCall(() => {
42+
const port = server.address().port;
43+
const client = http2.connect(`http://localhost:${port}`);
44+
45+
const countdown = new Countdown(serverHttp2StreamCreationCount, () => {
46+
client.close();
47+
server.close();
48+
});
49+
50+
const stream = client.request({});
51+
stream.on('response', common.mustCall(() => {
52+
countdown.dec();
53+
}));
54+
55+
client.on('stream', common.mustCall((pushStream) => {
56+
pushStream.on('push', common.mustCall(() => {
57+
countdown.dec();
58+
}));
59+
}));
60+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.