(...args)
| 324 | // See ProxyConfig in internal/http.js for how the connection should be handled |
| 325 | // when the agent is configured to use a proxy server. |
| 326 | function createConnection(...args) { |
| 327 | // XXX: This signature (port, host, options) is different from all the other |
| 328 | // createConnection() methods. |
| 329 | let options, cb; |
| 330 | if (args[0] !== null && typeof args[0] === 'object') { |
| 331 | options = args[0]; |
| 332 | } else if (args[1] !== null && typeof args[1] === 'object') { |
| 333 | options = { ...args[1] }; |
| 334 | } else if (args[2] === null || typeof args[2] !== 'object') { |
| 335 | options = {}; |
| 336 | } else { |
| 337 | options = { ...args[2] }; |
| 338 | } |
| 339 | if (typeof args[0] === 'number') { |
| 340 | options.port = args[0]; |
| 341 | } |
| 342 | if (typeof args[1] === 'string') { |
| 343 | options.host = args[1]; |
| 344 | } |
| 345 | if (typeof args[args.length - 1] === 'function') { |
| 346 | cb = args[args.length - 1]; |
| 347 | } |
| 348 | |
| 349 | debug('createConnection', options); |
| 350 | |
| 351 | if (options._agentKey) { |
| 352 | const session = this._getSession(options._agentKey); |
| 353 | if (session) { |
| 354 | debug('reuse session for %j', options._agentKey); |
| 355 | options = { |
| 356 | session, |
| 357 | ...options, |
| 358 | }; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | let socket; |
| 363 | const tunnelConfig = getTunnelConfigForProxiedHttps(this, options); |
| 364 | debug(`https createConnection should use proxy for ${options.host}:${options.port}:`, tunnelConfig); |
| 365 | |
| 366 | if (!tunnelConfig) { |
| 367 | socket = tls.connect(options); |
| 368 | } else { |
| 369 | const connectOptions = { |
| 370 | ...this[kProxyConfig].proxyConnectionOptions, |
| 371 | }; |
| 372 | debug('Create proxy socket', connectOptions); |
| 373 | const onError = (err) => { |
| 374 | cleanupAndPropagate(err, socket); |
| 375 | }; |
| 376 | const proxyTunnelTimeout = tunnelConfig.requestOptions.timeout; |
| 377 | const onTimeout = () => { |
| 378 | const err = new ERR_PROXY_TUNNEL(`Connection to establish proxy tunnel timed out after ${proxyTunnelTimeout}ms`); |
| 379 | err.proxyTunnelTimeout = proxyTunnelTimeout; |
| 380 | cleanupAndPropagate(err, socket); |
| 381 | }; |
| 382 | const cleanupAndPropagate = once((err, currentSocket) => { |
| 383 | debug('cleanupAndPropagate', err); |
nothing calls this directly
no test coverage detected
searching dependent graphs…