TooTallNate / proxy-agents

Node.js HTTP Proxy Agents Monorepo
https://proxy-agents.n8.io
872 stars 229 forks source link

connectOpts are ignored when upgrading socket connection to TLS #194

Open joerg1985 opened 1 year ago

joerg1985 commented 1 year ago

I need to set a client certificate to connect to our service, when using a proxy the connection fails. new HttpsProxyAgent(process.env.HTTPS_PROXY, { pfx: buffer })

These connectOpts options are only used to connect, but when the connection is upgraded the connectOpts are ignored. https://github.com/TooTallNate/proxy-agents/blob/e1e80ab78cef88fd1e800b07611581dce3142550/packages/https-proxy-agent/src/index.ts#L144-L148

My perfered option would be to have second argument to the HttpsProxyAgent class with upgradeOpts. new HttpsProxyAgent(process.env.HTTPS_PROXY, {}, { pfx: buffer })

When upgrading the connection these could be used with the regular options:

...omit(opts, 'host', 'path', 'port'),
...this.upgradeOpts,

With the new argument it would be even possible to connect to a https proxy with a client certificate and to the remote server with another client certificate. When using the original connectOpts setting a client certificate might disturb the connection to the proxy server.