Skip to content

Commit b3860aa

Browse files
authored
Remove secureProxy getter (#188)
1 parent d2d03d5 commit b3860aa

File tree

5 files changed

+13
-45
lines changed

5 files changed

+13
-45
lines changed

.changeset/lovely-phones-kick.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'https-proxy-agent': major
3+
'http-proxy-agent': major
4+
---
5+
6+
Remove `secureProxy` getter
7+
8+
It was not meant to be a public property. If you were using it, just use `agent.proxy.protocol === 'https:'` instead.

packages/http-proxy-agent/src/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ interface HttpProxyAgentClientRequest extends http.ClientRequest {
3535
_implicitHeader(): void;
3636
}
3737

38-
function isHTTPS(protocol?: string | null): boolean {
39-
return typeof protocol === 'string' ? /^https:?$/i.test(protocol) : false;
40-
}
41-
4238
/**
4339
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
4440
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
@@ -50,10 +46,6 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
5046
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
5147
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
5248

53-
get secureProxy() {
54-
return isHTTPS(this.proxy.protocol);
55-
}
56-
5749
constructor(proxy: Uri | URL, opts?: HttpProxyAgentOptions<Uri>) {
5850
super(opts);
5951
this.proxy = typeof proxy === 'string' ? new URL(proxy) : proxy;
@@ -67,7 +59,7 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
6759
);
6860
const port = this.proxy.port
6961
? parseInt(this.proxy.port, 10)
70-
: this.secureProxy
62+
: this.proxy.protocol === 'https:'
7163
? 443
7264
: 80;
7365
this.connectOpts = {
@@ -159,7 +151,7 @@ export class HttpProxyAgent<Uri extends string> extends Agent {
159151

160152
// Create a socket connection to the proxy server.
161153
let socket: net.Socket;
162-
if (this.secureProxy) {
154+
if (this.proxy.protocol === 'https:') {
163155
debug('Creating `tls.Socket`: %o', this.connectOpts);
164156
socket = tls.connect(this.connectOpts);
165157
} else {

packages/http-proxy-agent/test/test.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,6 @@ describe('HttpProxyAgent', () => {
6767
const agent = new HttpProxyAgent(proxyUrl);
6868
assert.equal(80, agent.defaultPort);
6969
});
70-
describe('secureProxy', () => {
71-
it('should be `false` when "http:" protocol is used', () => {
72-
const agent = new HttpProxyAgent(
73-
`http://127.0.0.1:${proxyUrl.port}`
74-
);
75-
assert.equal(false, agent.secureProxy);
76-
});
77-
it('should be `true` when "https:" protocol is used', () => {
78-
const agent = new HttpProxyAgent(
79-
`https://127.0.0.1:${proxyUrl.port}`
80-
);
81-
assert.equal(true, agent.secureProxy);
82-
});
83-
});
8470
});
8571

8672
describe('"http" module', () => {

packages/https-proxy-agent/src/index.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
4747
proxyHeaders: OutgoingHttpHeaders | (() => OutgoingHttpHeaders);
4848
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
4949

50-
get secureProxy() {
51-
return isHTTPS(this.proxy.protocol);
52-
}
53-
5450
constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>) {
5551
super(opts);
5652
this.options = { path: undefined };
@@ -65,7 +61,7 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
6561
);
6662
const port = this.proxy.port
6763
? parseInt(this.proxy.port, 10)
68-
: this.secureProxy
64+
: this.proxy.protocol === 'https:'
6965
? 443
7066
: 80;
7167
this.connectOpts = {
@@ -85,15 +81,15 @@ export class HttpsProxyAgent<Uri extends string> extends Agent {
8581
req: http.ClientRequest,
8682
opts: AgentConnectOpts
8783
): Promise<net.Socket> {
88-
const { proxy, secureProxy } = this;
84+
const { proxy } = this;
8985

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

9490
// Create a socket connection to the proxy server.
9591
let socket: net.Socket;
96-
if (secureProxy) {
92+
if (proxy.protocol === 'https:') {
9793
debug('Creating `tls.Socket`: %o', this.connectOpts);
9894
socket = tls.connect(this.connectOpts);
9995
} else {
@@ -191,10 +187,6 @@ function resume(socket: net.Socket | tls.TLSSocket): void {
191187
socket.resume();
192188
}
193189

194-
function isHTTPS(protocol?: string | null): boolean {
195-
return typeof protocol === 'string' ? /^https:?$/i.test(protocol) : false;
196-
}
197-
198190
function omit<T extends object, K extends [...(keyof T)[]]>(
199191
obj: T,
200192
...keys: K

packages/https-proxy-agent/test/test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ describe('HttpsProxyAgent', () => {
8383
assert.equal(proxyUrl.hostname, agent.proxy.hostname);
8484
assert.equal(proxyUrl.port, agent.proxy.port);
8585
});
86-
describe('secureProxy', () => {
87-
it('should be `false` when "http:" protocol is used', () => {
88-
const agent = new HttpsProxyAgent(proxyUrl);
89-
assert.equal(false, agent.secureProxy);
90-
});
91-
it('should be `true` when "https:" protocol is used', () => {
92-
const agent = new HttpsProxyAgent(sslProxyUrl);
93-
assert.equal(true, agent.secureProxy);
94-
});
95-
});
9686
});
9787

9888
describe('"http" module', () => {

0 commit comments

Comments
 (0)