mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
f55ee6e24a
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>
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const h2 = require('http2');
|
|
|
|
const serverTimeout = common.platformTimeout(200);
|
|
const callTimeout = common.platformTimeout(20);
|
|
const minRuns = Math.ceil(serverTimeout / callTimeout) * 2;
|
|
const mustNotCall = common.mustNotCall();
|
|
|
|
const server = h2.createServer();
|
|
server.timeout = serverTimeout;
|
|
|
|
server.on('request', (req, res) => res.end());
|
|
server.on('timeout', mustNotCall);
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
|
|
const url = `http://localhost:${port}`;
|
|
const client = h2.connect(url);
|
|
makeReq(minRuns);
|
|
|
|
function makeReq(attempts) {
|
|
const request = client.request({
|
|
':path': '/foobar',
|
|
':method': 'GET',
|
|
':scheme': 'http',
|
|
':authority': `localhost:${port}`,
|
|
});
|
|
request.resume();
|
|
request.end();
|
|
|
|
request.on('end', () => {
|
|
if (attempts) {
|
|
setTimeout(() => makeReq(attempts - 1), callTimeout);
|
|
} else {
|
|
server.removeListener('timeout', mustNotCall);
|
|
client.destroy();
|
|
server.close();
|
|
}
|
|
});
|
|
}
|
|
}));
|