| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 573b0b7 commit 6c3e426
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1209,6 +1209,13 @@ Emitted when server sends a response. | |||
| 1209 | 1209 | ||
| 1210 | 1210 | Emitted when a stream is created on the client. | |
| 1211 | 1211 | ||
| 1212 | + `http2.client.stream.start` | ||
| 1213 | + | ||
| 1214 | + * `stream` {ClientHttp2Stream} | ||
| 1215 | + * `headers` {HTTP/2 Headers Object} | ||
| 1216 | + | ||
| 1217 | + Emitted when a stream is started on the client. | ||
| 1218 | + | ||
| 1212 | 1219 | #### Modules | |
| 1213 | 1220 | ||
| 1214 | 1221 | > Stability: 1 - Experimental | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,6 +191,7 @@ const { _connectionListener: httpConnectionListener } = http; | |||
| 191 | 191 | ||
| 192 | 192 | const dc = require('diagnostics_channel'); | |
| 193 | 193 | const onClientStreamCreatedChannel = dc.channel('http2.client.stream.created'); | |
| 194 | + const onClientStreamStartChannel = dc.channel('http2.client.stream.start'); | ||
| 194 | 195 | ||
| 195 | 196 | let debug = require('internal/util/debuglog').debuglog('http2', (fn) => { | |
| 196 | 197 | debug = fn; | |
@@ -389,6 +390,12 @@ function onSessionHeaders(handle, id, cat, flags, headers, sensitiveHeaders) { | |||
| 389 | 390 | headers: obj, | |
| 390 | 391 | }); | |
| 391 | 392 | } | |
| 393 | + if (onClientStreamStartChannel.hasSubscribers) { | ||
| 394 | + onClientStreamStartChannel.publish({ | ||
| 395 | + stream, | ||
| 396 | + headers: obj, | ||
| 397 | + }); | ||
| 398 | + } | ||
| 392 | 399 | if (endOfStream) { | |
| 393 | 400 | stream.push(null); | |
| 394 | 401 | } | |
@@ -725,7 +732,7 @@ function onGoawayData(code, lastStreamID, buf) { | |||
| 725 | 732 | // When a ClientHttp2Session is first created, the socket may not yet be | |
| 726 | 733 | // connected. If request() is called during this time, the actual request | |
| 727 | 734 | // will be deferred until the socket is ready to go. | |
| 728 | - function requestOnConnect(headers, options) { | ||
| 735 | + function requestOnConnect(headersList, headersParam, options) { | ||
| 729 | 736 | const session = this[kSession]; | |
| 730 | 737 | ||
| 731 | 738 | // At this point, the stream should have already been destroyed during | |
@@ -752,7 +759,7 @@ function requestOnConnect(headers, options) { | |||
| 752 | 759 | ||
| 753 | 760 | // `ret` will be either the reserved stream ID (if positive) | |
| 754 | 761 | // or an error code (if negative) | |
| 755 | - const ret = session[kHandle].request(headers, | ||
| 762 | + const ret = session[kHandle].request(headersList, | ||
| 756 | 763 | streamOptions, | |
| 757 | 764 | options.parent | 0, | |
| 758 | 765 | options.weight | 0, | |
@@ -784,6 +791,12 @@ function requestOnConnect(headers, options) { | |||
| 784 | 791 | return; | |
| 785 | 792 | } | |
| 786 | 793 | this[kInit](ret.id(), ret); | |
| 794 | + if (onClientStreamStartChannel.hasSubscribers) { | ||
| 795 | + onClientStreamStartChannel.publish({ | ||
| 796 | + stream: this, | ||
| 797 | + headers: headersParam, | ||
| 798 | + }); | ||
| 799 | + } | ||
| 787 | 800 | } | |
| 788 | 801 | ||
| 789 | 802 | // Validates that priority options are correct, specifically: | |
@@ -1861,7 +1874,7 @@ class ClientHttp2Session extends Http2Session { | |||
| 1861 | 1874 | } | |
| 1862 | 1875 | } | |
| 1863 | 1876 | ||
| 1864 | - const onConnect = reqAsync.bind(requestOnConnect.bind(stream, headersList, options)); | ||
| 1877 | + const onConnect = reqAsync.bind(requestOnConnect.bind(stream, headersList, headersParam, options)); | ||
| 1865 | 1878 | if (this.connecting) { | |
| 1866 | 1879 | if (this[kPendingRequestCalls] !== null) { | |
| 1867 | 1880 | this[kPendingRequestCalls].push(onConnect); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,59 @@ | |||
| 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.start' channel when | ||
| 9 | + // ClientHttp2Streams are started 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 clientHttp2StreamStartCount = 2; | ||
| 20 | + | ||
| 21 | + dc.subscribe('http2.client.stream.start', 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. | ||
| 24 | + assert.ok(stream instanceof Duplex); | ||
| 25 | + assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream'); | ||
| 26 | + assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object'); | ||
| 27 | + }, clientHttp2StreamStartCount)); | ||
| 28 | + | ||
| 29 | + const server = http2.createServer(); | ||
| 30 | + server.on('stream', common.mustCall((stream) => { | ||
| 31 | + stream.respond(); | ||
| 32 | + stream.end(); | ||
| 33 | + | ||
| 34 | + stream.pushStream({}, common.mustSucceed((pushStream) => { | ||
| 35 | + pushStream.respond(); | ||
| 36 | + pushStream.end(); | ||
| 37 | + }, 1)); | ||
| 38 | + }, 1)); | ||
| 39 | + | ||
| 40 | + server.listen(0, common.mustCall(() => { | ||
| 41 | + const port = server.address().port; | ||
| 42 | + const client = http2.connect(`http://localhost:${port}`); | ||
| 43 | + | ||
| 44 | + const countdown = new Countdown(clientHttp2StreamStartCount, () => { | ||
| 45 | + client.close(); | ||
| 46 | + server.close(); | ||
| 47 | + }); | ||
| 48 | + | ||
| 49 | + const stream = client.request({}); | ||
| 50 | + stream.on('response', common.mustCall(() => { | ||
| 51 | + countdown.dec(); | ||
| 52 | + })); | ||
| 53 | + | ||
| 54 | + client.on('stream', common.mustCall((pushStream) => { | ||
| 55 | + pushStream.on('push', common.mustCall(() => { | ||
| 56 | + countdown.dec(); | ||
| 57 | + }, 1)); | ||
| 58 | + }, 1)); | ||
| 59 | + }, 1)); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments