diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 6bf2edd148..b1a424279b 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -760,7 +760,7 @@ const deprecateWeight = deprecateProperty('weight', // When a ClientHttp2Session is first created, the socket may not yet be // connected. If request() is called during this time, the actual request // will be deferred until the socket is ready to go. -function requestOnConnect(headersList, headersParam, options) { +function requestOnConnect(headersList, options) { const session = this[kSession]; // At this point, the stream should have already been destroyed during @@ -824,7 +824,7 @@ function requestOnConnect(headersList, headersParam, options) { if (onClientStreamStartChannel.hasSubscribers) { onClientStreamStartChannel.publish({ stream: this, - headers: headersParam, + headers: this.sentHeaders, }); } } @@ -1888,7 +1888,7 @@ class ClientHttp2Session extends Http2Session { } } - const onConnect = reqAsync.bind(requestOnConnect.bind(stream, headersList, headersParam, options)); + const onConnect = reqAsync.bind(requestOnConnect.bind(stream, headersList, options)); if (this.connecting) { if (this[kPendingRequestCalls] !== null) { this[kPendingRequestCalls].push(onConnect); @@ -1906,7 +1906,7 @@ class ClientHttp2Session extends Http2Session { if (onClientStreamCreatedChannel.hasSubscribers) { onClientStreamCreatedChannel.publish({ stream, - headers: headersParam, + headers: stream.sentHeaders, }); } diff --git a/test/parallel/test-diagnostics-channel-http2-client-stream-created.js b/test/parallel/test-diagnostics-channel-http2-client-stream-created.js index 75806db591..53e3b4b11e 100644 --- a/test/parallel/test-diagnostics-channel-http2-client-stream-created.js +++ b/test/parallel/test-diagnostics-channel-http2-client-stream-created.js @@ -18,6 +18,9 @@ const { Duplex } = require('stream'); const clientHttp2StreamCreationCount = 2; +let countdown; +let port; + dc.subscribe('http2.client.stream.created', common.mustCall(({ stream, headers }) => { // Since ClientHttp2Stream is not exported from any module, this just checks // if the stream is an instance of Duplex and the constructor name is @@ -25,6 +28,28 @@ dc.subscribe('http2.client.stream.created', common.mustCall(({ stream, headers } assert.ok(stream instanceof Duplex); assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream'); assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object'); + if (countdown.remaining === clientHttp2StreamCreationCount) { + // The request stream headers. + assert.deepStrictEqual(headers, { + '__proto__': null, + ':method': 'GET', + ':authority': `localhost:${port}`, + ':scheme': 'http', + ':path': '/', + 'requestHeader': 'requestValue', + }); + } else { + // The push stream headers. + assert.deepStrictEqual(headers, { + '__proto__': null, + ':method': 'GET', + ':authority': `localhost:${port}`, + ':scheme': 'http', + ':path': '/', + [http2.sensitiveHeaders]: [], + 'pushheader': 'pushValue', + }); + } }, clientHttp2StreamCreationCount)); const server = http2.createServer(); @@ -32,22 +57,22 @@ server.on('stream', common.mustCall((stream) => { stream.respond(); stream.end(); - stream.pushStream({}, common.mustSucceed((pushStream) => { + stream.pushStream({ 'pushHeader': 'pushValue' }, common.mustSucceed((pushStream) => { pushStream.respond(); pushStream.end(); }, 1)); }, 1)); server.listen(0, common.mustCall(() => { - const port = server.address().port; + port = server.address().port; const client = http2.connect(`http://localhost:${port}`); - const countdown = new Countdown(clientHttp2StreamCreationCount, () => { + countdown = new Countdown(clientHttp2StreamCreationCount, () => { client.close(); server.close(); }); - const stream = client.request({}); + const stream = client.request(['requestHeader', 'requestValue']); stream.on('response', common.mustCall(() => { countdown.dec(); })); diff --git a/test/parallel/test-diagnostics-channel-http2-client-stream-start.js b/test/parallel/test-diagnostics-channel-http2-client-stream-start.js index e8edf3a0a4..36b9a5db4c 100644 --- a/test/parallel/test-diagnostics-channel-http2-client-stream-start.js +++ b/test/parallel/test-diagnostics-channel-http2-client-stream-start.js @@ -18,12 +18,38 @@ const { Duplex } = require('stream'); const clientHttp2StreamStartCount = 2; +let countdown; +let port; + dc.subscribe('http2.client.stream.start', common.mustCall(({ stream, headers }) => { // Since ClientHttp2Stream is not exported from any module, this just checks // if the stream is an instance of Duplex. assert.ok(stream instanceof Duplex); assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream'); assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object'); + + if (countdown.remaining === clientHttp2StreamStartCount) { + // The request stream headers. + assert.deepStrictEqual(headers, { + '__proto__': null, + ':method': 'GET', + ':authority': `localhost:${port}`, + ':scheme': 'http', + ':path': '/', + 'requestHeader': 'requestValue', + }); + } else { + // The push stream headers. + assert.deepStrictEqual(headers, { + '__proto__': null, + ':method': 'GET', + ':authority': `localhost:${port}`, + ':scheme': 'http', + ':path': '/', + [http2.sensitiveHeaders]: [], + 'pushheader': 'pushValue', + }); + } }, clientHttp2StreamStartCount)); const server = http2.createServer(); @@ -31,22 +57,22 @@ server.on('stream', common.mustCall((stream) => { stream.respond(); stream.end(); - stream.pushStream({}, common.mustSucceed((pushStream) => { + stream.pushStream({ 'pushHeader': 'pushValue' }, common.mustSucceed((pushStream) => { pushStream.respond(); pushStream.end(); }, 1)); }, 1)); server.listen(0, common.mustCall(() => { - const port = server.address().port; + port = server.address().port; const client = http2.connect(`http://localhost:${port}`); - const countdown = new Countdown(clientHttp2StreamStartCount, () => { + countdown = new Countdown(clientHttp2StreamStartCount, () => { client.close(); server.close(); }); - const stream = client.request({}); + const stream = client.request(['requestHeader', 'requestValue']); stream.on('response', common.mustCall(() => { countdown.dec(); }));