Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -824,7 +824,7 @@ function requestOnConnect(headersList, headersParam, options) {
if (onClientStreamStartChannel.hasSubscribers) {
onClientStreamStartChannel.publish({
stream: this,
headers: headersParam,
headers: this.sentHeaders,
});
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -1906,7 +1906,7 @@ class ClientHttp2Session extends Http2Session {
if (onClientStreamCreatedChannel.hasSubscribers) {
onClientStreamCreatedChannel.publish({
stream,
headers: headersParam,
headers: stream.sentHeaders,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,61 @@ 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
// 'ClientHttp2Stream'.
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();
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();
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,61 @@ 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();
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();
}));
Expand Down
Loading