({ allowH2, preferH2, useH2c, maxCachedSessions, socketPath, timeout, session: customSession, ...opts })
| 3181 | } |
| 3182 | }; |
| 3183 | function buildConnector({ allowH2, preferH2, useH2c, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) { |
| 3184 | if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) { |
| 3185 | throw new InvalidArgumentError("maxCachedSessions must be a positive integer or zero"); |
| 3186 | } |
| 3187 | const options = { path: socketPath, ...opts }; |
| 3188 | const sessionCache = new SessionCache(maxCachedSessions == null ? 100 : maxCachedSessions); |
| 3189 | timeout = timeout == null ? 1e4 : timeout; |
| 3190 | allowH2 = allowH2 != null ? allowH2 : true; |
| 3191 | return /* @__PURE__ */ __name(function connect({ hostname, host, protocol, port, servername, localAddress, httpSocket }, callback) { |
| 3192 | let socket; |
| 3193 | if (protocol === "https:") { |
| 3194 | if (!tls) { |
| 3195 | tls = require("node:tls"); |
| 3196 | } |
| 3197 | servername = servername || options.servername || util.getServerName(host) || null; |
| 3198 | const sessionKey = servername || hostname; |
| 3199 | assert(sessionKey); |
| 3200 | const session = customSession || sessionCache.get(sessionKey) || null; |
| 3201 | port = port || 443; |
| 3202 | socket = tls.connect({ |
| 3203 | highWaterMark: 16384, |
| 3204 | // TLS in node can't have bigger HWM anyway... |
| 3205 | ...options, |
| 3206 | servername, |
| 3207 | session, |
| 3208 | localAddress, |
| 3209 | ALPNProtocols: allowH2 ? preferH2 ? ["h2", "http/1.1"] : ["http/1.1", "h2"] : ["http/1.1"], |
| 3210 | socket: httpSocket, |
| 3211 | // upgrade socket connection |
| 3212 | port, |
| 3213 | host: hostname |
| 3214 | }); |
| 3215 | socket.on("session", function(session2) { |
| 3216 | sessionCache.set(sessionKey, session2); |
| 3217 | }); |
| 3218 | } else { |
| 3219 | assert(!httpSocket, "httpSocket can only be sent on TLS update"); |
| 3220 | port = port || 80; |
| 3221 | socket = net.connect({ |
| 3222 | highWaterMark: 64 * 1024, |
| 3223 | // Same as nodejs fs streams. |
| 3224 | ...options, |
| 3225 | localAddress, |
| 3226 | port, |
| 3227 | host: hostname |
| 3228 | }); |
| 3229 | if (useH2c === true) { |
| 3230 | socket.alpnProtocol = "h2"; |
| 3231 | } |
| 3232 | } |
| 3233 | if (options.keepAlive == null || options.keepAlive) { |
| 3234 | const keepAliveInitialDelay = options.keepAliveInitialDelay === void 0 ? 6e4 : options.keepAliveInitialDelay; |
| 3235 | socket.setKeepAlive(true, keepAliveInitialDelay); |
| 3236 | } |
| 3237 | const clearConnectTimeout = util.setupConnectTimeout(new WeakRef(socket), { timeout, hostname, port }); |
| 3238 | socket.setNoDelay(true).once(protocol === "https:" ? "secureConnect" : "connect", function() { |
| 3239 | queueMicrotask(clearConnectTimeout); |
| 3240 | if (callback) { |
no test coverage detected
searching dependent graphs…