diff --git a/.changeset/lovely-phones-kick.md b/.changeset/lovely-phones-kick.md new file mode 100644 index 00000000..f0216c97 --- /dev/null +++ b/.changeset/lovely-phones-kick.md @@ -0,0 +1,8 @@ +--- +'https-proxy-agent': major +'http-proxy-agent': major +--- + +Remove `secureProxy` getter + +It was not meant to be a public property. If you were using it, just use `agent.proxy.protocol === 'https:'` instead. diff --git a/packages/http-proxy-agent/src/index.ts b/packages/http-proxy-agent/src/index.ts index 7c2a18d9..e373c749 100644 --- a/packages/http-proxy-agent/src/index.ts +++ b/packages/http-proxy-agent/src/index.ts @@ -35,10 +35,6 @@ interface HttpProxyAgentClientRequest extends http.ClientRequest { _implicitHeader(): void; } -function isHTTPS(protocol?: string | null): boolean { - return typeof protocol === 'string' ? /^https:?$/i.test(protocol) : false; -} - /** * The `HttpProxyAgent` implements an HTTP Agent subclass that connects * to the specified "HTTP proxy server" in order to proxy HTTP requests. @@ -50,10 +46,6 @@ export class HttpProxyAgent extends Agent { proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders); connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions; - get secureProxy() { - return isHTTPS(this.proxy.protocol); - } - constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions) { super(opts); this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy; @@ -67,7 +59,7 @@ export class HttpProxyAgent extends Agent { ); const port = this.proxy.port ? parseInt(this.proxy.port, 10) - : this.secureProxy + : this.proxy.protocol === 'https:' ? 443 : 80; this.connectOpts = { @@ -159,7 +151,7 @@ export class HttpProxyAgent extends Agent { // Create a socket connection to the proxy server. let socket: net.Socket; - if (this.secureProxy) { + if (this.proxy.protocol === 'https:') { debug('Creating `tls.Socket`: %o', this.connectOpts); socket = tls.connect(this.connectOpts); } else { diff --git a/packages/http-proxy-agent/test/test.ts b/packages/http-proxy-agent/test/test.ts index 40e74041..77948f69 100644 --- a/packages/http-proxy-agent/test/test.ts +++ b/packages/http-proxy-agent/test/test.ts @@ -67,20 +67,6 @@ describe('HttpProxyAgent', () => { const agent = new HttpProxyAgent(proxyUrl); assert.equal(80, agent.defaultPort); }); - describe('secureProxy', () => { - it('should be `false` when "http:" protocol is used', () => { - const agent = new HttpProxyAgent( - `http://127.0.0.1:${proxyUrl.port}` - ); - assert.equal(false, agent.secureProxy); - }); - it('should be `true` when "https:" protocol is used', () => { - const agent = new HttpProxyAgent( - `https://127.0.0.1:${proxyUrl.port}` - ); - assert.equal(true, agent.secureProxy); - }); - }); }); describe('"http" module', () => { diff --git a/packages/https-proxy-agent/src/index.ts b/packages/https-proxy-agent/src/index.ts index 6bdd9ae5..d136b0c5 100644 --- a/packages/https-proxy-agent/src/index.ts +++ b/packages/https-proxy-agent/src/index.ts @@ -47,10 +47,6 @@ export class HttpsProxyAgent extends Agent { proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders); connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions; - get secureProxy() { - return isHTTPS(this.proxy.protocol); - } - constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions) { super(opts); this.options = { path: undefined }; @@ -65,7 +61,7 @@ export class HttpsProxyAgent extends Agent { ); const port = this.proxy.port ? parseInt(this.proxy.port, 10) - : this.secureProxy + : this.proxy.protocol === 'https:' ? 443 : 80; this.connectOpts = { @@ -85,7 +81,7 @@ export class HttpsProxyAgent extends Agent { req: http.ClientRequest, opts: AgentConnectOpts ): Promise { - const { proxy, secureProxy } = this; + const { proxy } = this; if (!opts.host) { throw new TypeError('No "host" provided'); @@ -93,7 +89,7 @@ export class HttpsProxyAgent extends Agent { // Create a socket connection to the proxy server. let socket: net.Socket; - if (secureProxy) { + if (proxy.protocol === 'https:') { debug('Creating `tls.Socket`: %o', this.connectOpts); socket = tls.connect(this.connectOpts); } else { @@ -191,10 +187,6 @@ function resume(socket: net.Socket | tls.TLSSocket): void { socket.resume(); } -function isHTTPS(protocol?: string | null): boolean { - return typeof protocol === 'string' ? /^https:?$/i.test(protocol) : false; -} - function omit( obj: T, ...keys: K diff --git a/packages/https-proxy-agent/test/test.ts b/packages/https-proxy-agent/test/test.ts index 0e97c674..992c7610 100644 --- a/packages/https-proxy-agent/test/test.ts +++ b/packages/https-proxy-agent/test/test.ts @@ -83,16 +83,6 @@ describe('HttpsProxyAgent', () => { assert.equal(proxyUrl.hostname, agent.proxy.hostname); assert.equal(proxyUrl.port, agent.proxy.port); }); - describe('secureProxy', () => { - it('should be `false` when "http:" protocol is used', () => { - const agent = new HttpsProxyAgent(proxyUrl); - assert.equal(false, agent.secureProxy); - }); - it('should be `true` when "https:" protocol is used', () => { - const agent = new HttpsProxyAgent(sslProxyUrl); - assert.equal(true, agent.secureProxy); - }); - }); }); describe('"http" module', () => {