http2: report sent headers object in client stream dcs · nodejs/node@b7ea39d

@@ -18,36 +18,61 @@ const { Duplex } = require('stream');

18181919

const clientHttp2StreamCreationCount = 2;

202021+

let countdown;

22+

let port;

23+2124

dc.subscribe('http2.client.stream.created', common.mustCall(({ stream, headers }) => {

2225

// Since ClientHttp2Stream is not exported from any module, this just checks

2326

// if the stream is an instance of Duplex and the constructor name is

2427

// 'ClientHttp2Stream'.

2528

assert.ok(stream instanceof Duplex);

2629

assert.strictEqual(stream.constructor.name, 'ClientHttp2Stream');

2730

assert.ok(headers && !Array.isArray(headers) && typeof headers === 'object');

31+

if (countdown.remaining === clientHttp2StreamCreationCount) {

32+

// The request stream headers.

33+

assert.deepStrictEqual(headers, {

34+

'__proto__': null,

35+

':method': 'GET',

36+

':authority': `localhost:${port}`,

37+

':scheme': 'http',

38+

':path': '/',

39+

'requestHeader': 'requestValue',

40+

});

41+

} else {

42+

// The push stream headers.

43+

assert.deepStrictEqual(headers, {

44+

'__proto__': null,

45+

':method': 'GET',

46+

':authority': `localhost:${port}`,

47+

':scheme': 'http',

48+

':path': '/',

49+

[http2.sensitiveHeaders]: [],

50+

'pushheader': 'pushValue',

51+

});

52+

}

2853

}, clientHttp2StreamCreationCount));

29543055

const server = http2.createServer();

3156

server.on('stream', common.mustCall((stream) => {

3257

stream.respond();

3358

stream.end();

345935-

stream.pushStream({}, common.mustSucceed((pushStream) => {

60+

stream.pushStream({ 'pushHeader': 'pushValue' }, common.mustSucceed((pushStream) => {

3661

pushStream.respond();

3762

pushStream.end();

3863

}, 1));

3964

}, 1));

40654166

server.listen(0, common.mustCall(() => {

42-

const port = server.address().port;

67+

port = server.address().port;

4368

const client = http2.connect(`http://localhost:${port}`);

446945-

const countdown = new Countdown(clientHttp2StreamCreationCount, () => {

70+

countdown = new Countdown(clientHttp2StreamCreationCount, () => {

4671

client.close();

4772

server.close();

4873

});

497450-

const stream = client.request({});

75+

const stream = client.request(['requestHeader', 'requestValue']);

5176

stream.on('response', common.mustCall(() => {

5277

countdown.dec();

5378

}));