Skip to content

Commit

Permalink
Remove secureProxy getter (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed May 24, 2023
1 parent d2d03d5 commit b3860aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 45 deletions.
8 changes: 8 additions & 0 deletions .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.
12 changes: 2 additions & 10 deletions packages/http-proxy-agent/src/index.ts
Expand Up @@ -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.
Expand All @@ -50,10 +46,6 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;

get secureProxy() {
return isHTTPS(this.proxy.protocol);
}

constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>) {
super(opts);
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
Expand All @@ -67,7 +59,7 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
);
const port = this.proxy.port
? parseInt(this.proxy.port, 10)
: this.secureProxy
: this.proxy.protocol === 'https:'
? 443
: 80;
this.connectOpts = {
Expand Down Expand Up @@ -159,7 +151,7 @@ export class HttpProxyAgent<Uri extends string> 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 {
Expand Down
14 changes: 0 additions & 14 deletions packages/http-proxy-agent/test/test.ts
Expand Up @@ -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', () => {
Expand Down
14 changes: 3 additions & 11 deletions packages/https-proxy-agent/src/index.ts
Expand Up @@ -47,10 +47,6 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;

get secureProxy() {
return isHTTPS(this.proxy.protocol);
}

constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>) {
super(opts);
this.options = { path: undefined };
Expand All @@ -65,7 +61,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
);
const port = this.proxy.port
? parseInt(this.proxy.port, 10)
: this.secureProxy
: this.proxy.protocol === 'https:'
? 443
: 80;
this.connectOpts = {
Expand All @@ -85,15 +81,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
req: http.ClientRequest,
opts: AgentConnectOpts
): Promise<net.Socket> {
const { proxy, secureProxy } = this;
const { proxy } = this;

if (!opts.host) {
throw new TypeError('No "host" provided');
}

// 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 {
Expand Down Expand Up @@ -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<T extends object, K extends [...(keyof T)[]]>(
obj: T,
...keys: K
Expand Down
10 changes: 0 additions & 10 deletions packages/https-proxy-agent/test/test.ts
Expand Up @@ -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', () => {
Expand Down

1 comment on commit b3860aa

@vercel
Copy link

@vercel vercel bot commented on b3860aa May 24, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

proxy-agents – ./

proxy-agents-tootallnate.vercel.app
proxy-agents.vercel.app
proxy-agents-git-main-tootallnate.vercel.app

Please sign in to comment.