| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cff62e3 commit b99d131
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1200,6 +1200,15 @@ The event is emitted before the response is sent. | |||
| 1200 | 1200 | ||
| 1201 | 1201 | Emitted when server sends a response. | |
| 1202 | 1202 | ||
| 1203 | + #### HTTP/2 | ||
| 1204 | + | ||
| 1205 | + `http2.client.stream.created` | ||
| 1206 | + | ||
| 1207 | + * `stream` {ClientHttp2Stream} | ||
| 1208 | + * `headers` {HTTP/2 Headers Object} | ||
| 1209 | + | ||
| 1210 | + Emitted when a stream is created on the client. | ||
| 1211 | + | ||
| 1203 | 1212 | #### Modules | |
| 1204 | 1213 | ||
| 1205 | 1214 | `module.require.start` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,6 +188,10 @@ const { UV_EOF } = internalBinding('uv'); | |||
| 188 | 188 | ||
| 189 | 189 | const { StreamPipe } = internalBinding('stream_pipe'); | |
| 190 | 190 | const { _connectionListener: httpConnectionListener } = http; | |
| 191 | + | ||
| 192 | + const dc = require('diagnostics_channel'); | ||
| 193 | + const onClientStreamCreatedChannel = dc.channel('http2.client.stream.created'); | ||
| 194 | + | ||
| 191 | 195 | let debug = require('internal/util/debuglog').debuglog('http2', (fn) => { | |
| 192 | 196 | debug = fn; | |
| 193 | 197 | }); | |
@@ -379,6 +383,12 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) { | |||
| 379 | 383 | } else { | |
| 380 | 384 | // eslint-disable-next-line no-use-before-define | |
| 381 | 385 | stream = new ClientHttp2Stream(session, handle, id, {}); | |
| 386 | + if (onClientStreamCreatedChannel.hasSubscribers) { | ||
| 387 | + onClientStreamCreatedChannel.publish({ | ||
| 388 | + stream, | ||
| 389 | + headers: obj, | ||
| 390 | + }); | ||
| 391 | + } | ||
| 382 | 392 | if (endOfStream) { | |
| 383 | 393 | stream.push(null); | |
| 384 | 394 | } | |
@@ -1865,6 +1875,14 @@ class ClientHttp2Session extends Http2Session { | |||
| 1865 | 1875 | } else { | |
| 1866 | 1876 | onConnect(); | |
| 1867 | 1877 | } | |
| 1878 | + | ||
| 1879 | + if (onClientStreamCreatedChannel.hasSubscribers) { | ||
| 1880 | + onClientStreamCreatedChannel.publish({ | ||
| 1881 | + stream, | ||
| 1882 | + headers: headersParam, | ||
| 1883 | + }); | ||
| 1884 | + } | ||
| 1885 | + | ||
| 1868 | 1886 | return stream; | |
| 1869 | 1887 | } | |
| 1870 | 1888 | } | |
| 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