mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 16:22:29 +00:00

Make the `http2` module always available. The `--expose-http2` cli flag is made a non-op PR-URL: https://github.com/nodejs/node/pull/15535 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
34 lines
874 B
JavaScript
34 lines
874 B
JavaScript
'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();
|
|
}));
|
|
}));
|
|
}));
|