Skip to content

Commit 056f2e1

Browse files
authored
fix(cli): choose proxy agent based on requester protocol (stoplightio#2521)
1 parent e9edd2e commit 056f2e1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/cli/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { DEFAULT_REQUEST_OPTIONS } from '@stoplight/spectral-runtime';
66
import lintCommand from './commands/lint';
77

88
if (typeof process.env.PROXY === 'string') {
9-
const { protocol } = new URL(process.env.PROXY);
109
// eslint-disable-next-line @typescript-eslint/no-var-requires
1110
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent') as typeof import('hpagent');
12-
DEFAULT_REQUEST_OPTIONS.agent = new (protocol === 'https:' ? HttpsProxyAgent : HttpProxyAgent)({
13-
proxy: process.env.PROXY,
14-
});
11+
const httpAgent = new HttpProxyAgent({ proxy: process.env.PROXY });
12+
const httpsAgent = new HttpsProxyAgent({ proxy: process.env.PROXY });
13+
14+
DEFAULT_REQUEST_OPTIONS.agent = url => (url.protocol === 'http:' ? httpAgent : httpsAgent);
1515
}
1616

1717
export default yargs

0 commit comments

Comments
 (0)