MCPcopy Create free account
hub / github.com/angular/dev-infra / buildConnector

Function buildConnector

github-actions/browserstack/set-browserstack-env.js:2713–2782  ·  view source on GitHub ↗
(_a)

Source from the content-addressed store, hash-verified

2711 }
2712 if (this._sessionCache.size >= this._maxCachedSessions) {
2713 const { value: oldestKey } = this._sessionCache.keys().next();
2714 this._sessionCache.delete(oldestKey);
2715 }
2716 this._sessionCache.set(sessionKey, session);
2717 }
2718 };
2719 }
2720 function buildConnector(_a) {
2721 var _b = _a, { allowH2, maxCachedSessions, socketPath, timeout, session: customSession } = _b, opts = __objRest(_b, ["allowH2", "maxCachedSessions", "socketPath", "timeout", "session"]);
2722 if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) {
2723 throw new InvalidArgumentError("maxCachedSessions must be a positive integer or zero");
2724 }
2725 const options = __spreadValues({ path: socketPath }, opts);
2726 const sessionCache = new SessionCache(maxCachedSessions == null ? 100 : maxCachedSessions);
2727 timeout = timeout == null ? 1e4 : timeout;
2728 allowH2 = allowH2 != null ? allowH2 : false;
2729 return function connect({ hostname, host, protocol, port, servername, localAddress, httpSocket }, callback) {
2730 let socket;
2731 if (protocol === "https:") {
2732 if (!tls) {
2733 tls = __require("tls");
2734 }
2735 servername = servername || options.servername || util.getServerName(host) || null;
2736 const sessionKey = servername || hostname;
2737 assert(sessionKey);
2738 const session = customSession || sessionCache.get(sessionKey) || null;
2739 port = port || 443;
2740 socket = tls.connect(__spreadProps(__spreadValues({
2741 highWaterMark: 16384
2742 }, options), {
2743 servername,
2744 session,
2745 localAddress,
2746 // TODO(HTTP/2): Add support for h2c
2747 ALPNProtocols: allowH2 ? ["http/1.1", "h2"] : ["http/1.1"],
2748 socket: httpSocket,
2749 // upgrade socket connection
2750 port,
2751 host: hostname
2752 }));
2753 socket.on("session", function(session2) {
2754 sessionCache.set(sessionKey, session2);
2755 });
2756 } else {
2757 assert(!httpSocket, "httpSocket can only be sent on TLS update");
2758 port = port || 80;
2759 socket = net.connect(__spreadProps(__spreadValues({
2760 highWaterMark: 64 * 1024
2761 }, options), {
2762 localAddress,
2763 port,
2764 host: hostname
2765 }));
2766 }
2767 if (options.keepAlive == null || options.keepAlive) {
2768 const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay;
2769 socket.setKeepAlive(true, keepAliveInitialDelay);
2770 }

Callers 1

constructorMethod · 0.70

Calls 6

__objRestFunction · 0.70
__spreadValuesFunction · 0.70
__spreadPropsFunction · 0.70
getMethod · 0.45
onMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected