Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 40 additions & 22 deletions test/parallel/test-http2-connect.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
// Flags: --expose-http2
'use strict';

const { mustCall, hasCrypto, skip } = require('../common');
const { mustCall, hasCrypto, skip, expectsError } = require('../common');
if (!hasCrypto)
skip('missing crypto');
const { doesNotThrow } = require('assert');
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 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())));

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();
}
}));
}
}));
}

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to assume that there is no server listening on localhost?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to run fine with a server listening on 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
}));
}