mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 05:21:19 +00:00

PR-URL: https://github.com/nodejs/node/pull/17406 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> This is a significant cleanup and refactoring of the cleanup/close/destroy logic for Http2Stream and Http2Session. There are significant changes here in the timing and ordering of cleanup logic, JS apis. and various related necessary edits.
86 lines
2.3 KiB
JavaScript
86 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
// Tests http2.connect()
|
|
|
|
const common = require('../common');
|
|
const Countdown = require('../common/countdown');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const fixtures = require('../common/fixtures');
|
|
const h2 = require('http2');
|
|
const url = require('url');
|
|
const URL = url.URL;
|
|
|
|
{
|
|
const server = h2.createServer();
|
|
server.listen(0);
|
|
|
|
server.on('listening', common.mustCall(function() {
|
|
const port = this.address().port;
|
|
|
|
const items = [
|
|
[`http://localhost:${port}`],
|
|
[new URL(`http://localhost:${port}`)],
|
|
[url.parse(`http://localhost:${port}`)],
|
|
[{ port: port }, { protocol: 'http:' }],
|
|
[{ port: port, hostname: '127.0.0.1' }, { protocol: 'http:' }]
|
|
];
|
|
|
|
const serverClose = new Countdown(items.length + 1,
|
|
() => setImmediate(() => server.close()));
|
|
|
|
const maybeClose = common.mustCall((client) => {
|
|
client.close();
|
|
serverClose.dec();
|
|
}, items.length);
|
|
|
|
items.forEach((i) => {
|
|
const client =
|
|
h2.connect.apply(null, i)
|
|
.on('connect', common.mustCall(() => maybeClose(client)));
|
|
});
|
|
|
|
// Will fail because protocol does not match the server.
|
|
h2.connect({ port: port, protocol: 'https:' })
|
|
.on('error', common.mustCall(() => serverClose.dec()));
|
|
}));
|
|
}
|
|
|
|
|
|
{
|
|
|
|
const options = {
|
|
key: fixtures.readKey('agent3-key.pem'),
|
|
cert: fixtures.readKey('agent3-cert.pem')
|
|
};
|
|
|
|
const server = h2.createSecureServer(options);
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
|
|
const opts = { rejectUnauthorized: false };
|
|
|
|
const items = [
|
|
[`https://localhost:${port}`, opts],
|
|
[new URL(`https://localhost:${port}`), opts],
|
|
[url.parse(`https://localhost:${port}`), opts],
|
|
[{ port: port, protocol: 'https:' }, opts],
|
|
[{ port: port, hostname: '127.0.0.1', protocol: 'https:' }, opts]
|
|
];
|
|
|
|
const serverClose = new Countdown(items.length,
|
|
() => setImmediate(() => server.close()));
|
|
|
|
const maybeClose = common.mustCall((client) => {
|
|
client.close();
|
|
serverClose.dec();
|
|
}, items.length);
|
|
|
|
items.forEach((i) => {
|
|
const client =
|
|
h2.connect.apply(null, i)
|
|
.on('connect', common.mustCall(() => maybeClose(client)));
|
|
});
|
|
}));
|
|
}
|