| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 655326b commit 2cb86a3
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1201,6 +1201,15 @@ The event is emitted before the response is sent. | |||
| 1201 | 1201 | ||
| 1202 | 1202 | Emitted when server sends a response. | |
| 1203 | 1203 | ||
| 1204 | + #### HTTP/2 | ||
| 1205 | + | ||
| 1206 | + `http2.client.stream.created` | ||
| 1207 | + | ||
| 1208 | + * `stream` {ClientHttp2Stream} | ||
| 1209 | + * `headers` {HTTP/2 Headers Object} | ||
| 1210 | + | ||
| 1211 | + Emitted when a stream is created on the client. | ||
| 1212 | + | ||
| 1204 | 1213 | #### Modules | |
| 1205 | 1214 | ||
| 1206 | 1215 | `module.require.start` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -183,6 +183,10 @@ const { UV_EOF } = internalBinding('uv'); | |||
| 183 | 183 | ||
| 184 | 184 | const { StreamPipe } = internalBinding('stream_pipe'); | |
| 185 | 185 | const { _connectionListener: httpConnectionListener } = http; | |
| 186 | + | ||
| 187 | + const dc = require('diagnostics_channel'); | ||
| 188 | + const onClientStreamCreatedChannel = dc.channel('http2.client.stream.created'); | ||
| 189 | + | ||
| 186 | 190 | let debug = require('internal/util/debuglog').debuglog('http2', (fn) => { | |
| 187 | 191 | debug = fn; | |
| 188 | 192 | }); | |
@@ -371,6 +375,12 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) { | |||
| 371 | 375 | } else { | |
| 372 | 376 | // eslint-disable-next-line no-use-before-define | |
| 373 | 377 | stream = new ClientHttp2Stream(session, handle, id, {}); | |
| 378 | + if (onClientStreamCreatedChannel.hasSubscribers) { | ||
| 379 | + onClientStreamCreatedChannel.publish({ | ||
| 380 | + stream, | ||
| 381 | + headers: obj, | ||
| 382 | + }); | ||
| 383 | + } | ||
| 374 | 384 | if (endOfStream) { | |
| 375 | 385 | stream.push(null); | |
| 376 | 386 | } | |
@@ -1863,6 +1873,14 @@ class ClientHttp2Session extends Http2Session { | |||
| 1863 | 1873 | } else { | |
| 1864 | 1874 | onConnect(); | |
| 1865 | 1875 | } | |
| 1876 | + | ||
| 1877 | + if (onClientStreamCreatedChannel.hasSubscribers) { | ||
| 1878 | + onClientStreamCreatedChannel.publish({ | ||
| 1879 | + stream, | ||
| 1880 | + headers: headersParam, | ||
| 1881 | + }); | ||
| 1882 | + } | ||
| 1883 | + | ||
| 1866 | 1884 | return stream; | |
| 1867 | 1885 | } | |
| 1868 | 1886 | } | |
| Original file line number | Diff line number | Diff 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.client.stream.created' channel when | ||
| 9 | + // ClientHttp2Streams are created by both: | ||
| 10 | + // - the client calling ClientHttp2Session#request() | ||
| 11 | + // - in response to an incoming 'push' event from the server | ||
| 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 clientHttp2StreamCreationCount = 2; | ||
| 20 | + | ||
| 21 | + dc.subscribe('http2.client.stream.created', common.mustCall(({ stream, headers }) => { | ||
| 22 | + // Since ClientHttp2Stream is not exported from any module, this just checks | ||
| 23 | + // if the stream is an instance of Duplex and the constructor name is | ||
| 24 | + // 'ClientHttp2Stream'. | ||
| 25 | + assert.ok(stream instanceof Duplex); | ||
| 26 | + assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream'); | ||
| 27 | + assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object'); | ||
| 28 | + }, clientHttp2StreamCreationCount)); | ||
| 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 | + }, 1)); | ||
| 39 | + }, 1)); | ||
| 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(clientHttp2StreamCreationCount, () => { | ||
| 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 | + }, 1)); | ||
| 59 | + }, 1)); | ||
| 60 | + }, 1)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments