Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to specify options to the TLS upgrade #195

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/https-proxy-agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
readonly proxy: URL;
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
upgradeOpts: tls.ConnectionOptions;

constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>) {
constructor(
proxy: Uri | URL,
opts?: HttpsProxyAgentOptions<Uri>,
upgradeOpts?: tls.ConnectionOptions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not introduce a 3rd parameter. This should be a new option on the opts object. Perhaps something like opts.tlsUpgradeOpts.

Additionally, I think this should be an option on the AgentBase class, since http-proxy-agent, https-proxy-agent and socks-proxy-agent all upgrade the socket to TLS using similar logic. We can introduce a helper function (AgentBase#upgradeSocketToTls() or similar) which all of those packages would invoke when appropriate.

Finally, this needs some tests.

) {
super(opts);
this.options = { path: undefined };
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
Expand All @@ -71,6 +76,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
host,
port,
};
this.upgradeOpts = upgradeOpts ? {...upgradeOpts} : {}
}

/**
Expand Down Expand Up @@ -143,6 +149,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
const servername = opts.servername || opts.host;
return tls.connect({
...omit(opts, 'host', 'path', 'port'),
...this.upgradeOpts,
socket,
servername: net.isIP(servername) ? undefined : servername,
});
Expand Down