MCPcopy Index your code
hub / github.com/nodejs/node / connect

Function connect

lib/internal/http2/core.js:3592–3669  ·  view source on GitHub ↗
(authority, options, listener)

Source from the content-addressed store, hash-verified

3590}
3591
3592function connect(authority, options, listener) {
3593 if (typeof options === 'function') {
3594 listener = options;
3595 options = undefined;
3596 }
3597
3598 assertIsObject(options, 'options');
3599 options = { ...options };
3600
3601 let { maxOriginSetSize } = options;
3602 if (maxOriginSetSize != null) {
3603 validateNumber(maxOriginSetSize, 'options.maxOriginSetSize', 0);
3604 } else {
3605 maxOriginSetSize = 128;
3606 }
3607
3608 assertIsArray(options.remoteCustomSettings, 'options.remoteCustomSettings');
3609 if (options.remoteCustomSettings) {
3610 options.remoteCustomSettings = [ ...options.remoteCustomSettings ];
3611 if (options.remoteCustomSettings.length > MAX_ADDITIONAL_SETTINGS)
3612 throw new ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS();
3613 }
3614
3615 if (options.strictSingleValueFields !== undefined) {
3616 validateBoolean(
3617 options.strictSingleValueFields,
3618 'options.strictSingleValueFields',
3619 );
3620 } else {
3621 options.strictSingleValueFields = true;
3622 }
3623
3624 if (typeof authority === 'string')
3625 authority = new URL(authority);
3626
3627 assertIsObject(authority, 'authority', ['string', 'Object', 'URL']);
3628
3629 const protocol = authority.protocol || options.protocol || 'https:';
3630 const port = '' + (authority.port !== '' ?
3631 authority.port : (authority.protocol === 'http:' ? 80 : 443));
3632 let host = 'localhost';
3633
3634 if (authority.hostname) {
3635 host = authority.hostname;
3636
3637 if (host[0] === '[')
3638 host = host.slice(1, -1);
3639 } else if (authority.host) {
3640 host = authority.host;
3641 }
3642
3643 let socket;
3644 if (typeof options.createConnection === 'function') {
3645 socket = options.createConnection(authority, options);
3646 } else {
3647 switch (protocol) {
3648 case 'http:':
3649 socket = net.connect({ port, host, ...options });

Callers 1

core.jsFile · 0.70

Calls 5

initializeTLSOptionsFunction · 0.85
sliceMethod · 0.65
connectMethod · 0.65
createConnectionMethod · 0.45
onceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…