diff --git a/lib/dispatcher/proxy-agent.js b/lib/dispatcher/proxy-agent.js index cd9bc45ffad..9eb1ef8f67a 100644 --- a/lib/dispatcher/proxy-agent.js +++ b/lib/dispatcher/proxy-agent.js @@ -1,13 +1,12 @@ 'use strict' -const { kProxy, kClose, kDestroy, kDispatch, kConnector } = require('../core/symbols') +const { kProxy, kClose, kDestroy, kDispatch } = require('../core/symbols') const { URL } = require('node:url') const Agent = require('./agent') const Pool = require('./pool') const DispatcherBase = require('./dispatcher-base') const { InvalidArgumentError, RequestAbortedError, SecureProxyConnectionError } = require('../core/errors') const buildConnector = require('../core/connect') -const Client = require('./client') const kAgent = Symbol('proxy agent') const kClient = Symbol('proxy client') @@ -29,6 +28,7 @@ const noop = () => {} class ProxyClient extends DispatcherBase { #client = null + #connector = null constructor (origin, opts) { if (typeof origin === 'string') { origin = new URL(origin) @@ -40,7 +40,9 @@ class ProxyClient extends DispatcherBase { super() - this.#client = new Client(origin, opts) + // Store the connector for direct socket connections + this.#connector = opts?.connect || buildConnector(opts) + this.#client = new Pool(origin, opts) } async [kClose] () { @@ -54,7 +56,7 @@ class ProxyClient extends DispatcherBase { async [kDispatch] (opts, handler) { const { method, origin } = opts if (method === 'CONNECT') { - this.#client[kConnector]({ + this.#connector({ origin, port: opts.port || defaultProtocolPort(opts.protocol), path: opts.host, @@ -121,7 +123,7 @@ class ProxyAgent extends DispatcherBase { if (origin.protocol === 'http:') { return new ProxyClient(origin, options) } - return new Client(origin, options) + return new Pool(origin, options) } : undefined