node/test/parallel/test-http2-connect.js
James M Snell f55ee6e24a
http2: make --expose-http2 flag a non-op
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>
2017-09-28 02:01:06 -03:00

49 lines
1.3 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.destroy();
clients.delete(client);
if (clients.size === 0) {
server.close();
}
}));
}
}));
}
// check for https as protocol
{
const authority = 'https://localhost';
doesNotThrow(() => connect(authority));
}
// 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
}));
}