mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 09:08:46 +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.
53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
const { mustCall, hasCrypto, skip, expectsError } = require('../common');
|
|
if (!hasCrypto)
|
|
skip('missing crypto');
|
|
const { doesNotThrow, throws } = require('assert');
|
|
const { createServer, connect } = require('http2');
|
|
{
|
|
const server = createServer();
|
|
server.listen(0, mustCall(() => {
|
|
const authority = `http://localhost:${server.address().port}`;
|
|
const options = {};
|
|
const listener = () => mustCall();
|
|
|
|
const clients = new Set();
|
|
doesNotThrow(() => clients.add(connect(authority)));
|
|
doesNotThrow(() => clients.add(connect(authority, options)));
|
|
doesNotThrow(() => clients.add(connect(authority, options, listener())));
|
|
doesNotThrow(() => clients.add(connect(authority, listener())));
|
|
|
|
for (const client of clients) {
|
|
client.once('connect', mustCall((headers) => {
|
|
client.close();
|
|
clients.delete(client);
|
|
if (clients.size === 0) {
|
|
server.close();
|
|
}
|
|
}));
|
|
}
|
|
}));
|
|
}
|
|
|
|
// check for https as protocol
|
|
{
|
|
const authority = 'https://localhost';
|
|
doesNotThrow(() => {
|
|
// A socket error may or may not be reported, keep this as a non-op
|
|
// instead of a mustCall or mustNotCall
|
|
connect(authority).on('error', () => {});
|
|
});
|
|
}
|
|
|
|
// check for error for an invalid protocol (not http or https)
|
|
{
|
|
const authority = 'ssh://localhost';
|
|
throws(() => {
|
|
connect(authority);
|
|
}, expectsError({
|
|
code: 'ERR_HTTP2_UNSUPPORTED_PROTOCOL',
|
|
type: Error
|
|
}));
|
|
}
|