-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sentHeaders, sentTrailers, and sentInfoHeaders properties on `Http2Stream`. PR-URL: #18045 Fixes: #16619 Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const h2 = require('http2'); | ||
|
||
const server = h2.createServer(); | ||
|
||
server.on('stream', common.mustCall((stream) => { | ||
stream.additionalHeaders({ ':status': 102 }); | ||
assert.strictEqual(stream.sentInfoHeaders[0][':status'], 102); | ||
|
||
stream.respond({ abc: 'xyz' }, { | ||
getTrailers(headers) { | ||
headers.xyz = 'abc'; | ||
} | ||
}); | ||
assert.strictEqual(stream.sentHeaders.abc, 'xyz'); | ||
assert.strictEqual(stream.sentHeaders[':status'], 200); | ||
assert.notStrictEqual(stream.sentHeaders.date, undefined); | ||
stream.end(); | ||
stream.on('close', () => { | ||
assert.strictEqual(stream.sentTrailers.xyz, 'abc'); | ||
}); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = h2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request(); | ||
|
||
req.on('headers', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 102); | ||
})); | ||
|
||
assert.strictEqual(req.sentHeaders[':method'], 'GET'); | ||
assert.strictEqual(req.sentHeaders[':authority'], | ||
`localhost:${server.address().port}`); | ||
assert.strictEqual(req.sentHeaders[':scheme'], 'http'); | ||
assert.strictEqual(req.sentHeaders[':path'], '/'); | ||
req.resume(); | ||
req.on('close', () => { | ||
server.close(); | ||
client.close(); | ||
}); | ||
})); |