({ allowH2, maxCachedSessions, socketPath, timeout, ...opts })
| 53063 | if (this._sessionCache.size >= this._maxCachedSessions) { |
| 53064 | const { value: oldestKey } = this._sessionCache.keys().next(); |
| 53065 | this._sessionCache.delete(oldestKey); |
| 53066 | } |
| 53067 | this._sessionCache.set(sessionKey, session); |
| 53068 | } |
| 53069 | }; |
| 53070 | } |
| 53071 | function buildConnector({ allowH2, maxCachedSessions, socketPath, timeout, ...opts }) { |
| 53072 | if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) { |
| 53073 | throw new InvalidArgumentError("maxCachedSessions must be a positive integer or zero"); |
| 53074 | } |
| 53075 | const options = { path: socketPath, ...opts }; |
| 53076 | const sessionCache = new SessionCache(maxCachedSessions == null ? 100 : maxCachedSessions); |
| 53077 | timeout = timeout == null ? 1e4 : timeout; |
| 53078 | allowH2 = allowH2 != null ? allowH2 : false; |
| 53079 | return function connect3({ hostname, host, protocol, port, servername, localAddress, httpSocket }, callback) { |
| 53080 | let socket; |
| 53081 | if (protocol === "https:") { |
| 53082 | if (!tls2) { |
| 53083 | tls2 = require("tls"); |
| 53084 | } |
| 53085 | servername = servername || options.servername || util4.getServerName(host) || null; |
| 53086 | const sessionKey = servername || hostname; |
| 53087 | const session = sessionCache.get(sessionKey) || null; |
| 53088 | assert2(sessionKey); |
| 53089 | socket = tls2.connect({ |
| 53090 | highWaterMark: 16384, |
| 53091 | // TLS in node can't have bigger HWM anyway... |
| 53092 | ...options, |
| 53093 | servername, |
| 53094 | session, |
| 53095 | localAddress, |
| 53096 | // TODO(HTTP/2): Add support for h2c |
| 53097 | ALPNProtocols: allowH2 ? ["http/1.1", "h2"] : ["http/1.1"], |
| 53098 | socket: httpSocket, |
| 53099 | // upgrade socket connection |
| 53100 | port: port || 443, |
| 53101 | host: hostname |
| 53102 | }); |
| 53103 | socket.on("session", function(session2) { |
| 53104 | sessionCache.set(sessionKey, session2); |
| 53105 | }); |
| 53106 | } else { |
| 53107 | assert2(!httpSocket, "httpSocket can only be sent on TLS update"); |
| 53108 | socket = net3.connect({ |
| 53109 | highWaterMark: 64 * 1024, |
| 53110 | // Same as nodejs fs streams. |
| 53111 | ...options, |
| 53112 | localAddress, |
| 53113 | port: port || 80, |
| 53114 | host: hostname |
| 53115 | }); |
| 53116 | } |
| 53117 | if (options.keepAlive == null || options.keepAlive) { |
| 53118 | const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay; |
| 53119 | socket.setKeepAlive(true, keepAliveInitialDelay); |
| 53120 | } |
| 53121 | const cancelTimeout = setupTimeout2(() => onConnectTimeout(socket), timeout); |
| 53122 | socket.setNoDelay(true).once(protocol === "https:" ? "secureConnect" : "connect", function() { |
no test coverage detected
searching dependent graphs…