-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: custom promisify for http2.connect
... and some other cleanups PR-URL: #15207 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
4 changed files
with
59 additions
and
9 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
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,34 @@ | ||
// Flags: --expose-http2 | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const util = require('util'); | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream) => { | ||
stream.respond(); | ||
stream.end('ok'); | ||
})); | ||
server.listen(0, common.mustCall(() => { | ||
|
||
const connect = util.promisify(http2.connect); | ||
|
||
connect(`http://localhost:${server.address().port}`) | ||
.catch(common.mustNotCall()) | ||
.then(common.mustCall((client) => { | ||
assert(client); | ||
const req = client.request(); | ||
let data = ''; | ||
req.setEncoding('utf8'); | ||
req.on('data', (chunk) => data += chunk); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, 'ok'); | ||
client.destroy(); | ||
server.close(); | ||
})); | ||
})); | ||
})); |