Skip to content

Commit

Permalink
fix(cli): choose proxy agent based on requester protocol (#2521)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Aug 4, 2023
1 parent e9edd2e commit 056f2e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { DEFAULT_REQUEST_OPTIONS } from '@stoplight/spectral-runtime';
import lintCommand from './commands/lint';

if (typeof process.env.PROXY === 'string') {
const { protocol } = new URL(process.env.PROXY);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent') as typeof import('hpagent');
DEFAULT_REQUEST_OPTIONS.agent = new (protocol === 'https:' ? HttpsProxyAgent : HttpProxyAgent)({
proxy: process.env.PROXY,
});
const httpAgent = new HttpProxyAgent({ proxy: process.env.PROXY });
const httpsAgent = new HttpsProxyAgent({ proxy: process.env.PROXY });

DEFAULT_REQUEST_OPTIONS.agent = url => (url.protocol === 'http:' ? httpAgent : httpsAgent);
}

export default yargs
Expand Down

0 comments on commit 056f2e1

Please sign in to comment.