From 056f2e1eef966b807734fb00aae071411feabe75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Fri, 4 Aug 2023 10:23:50 +0200 Subject: [PATCH] fix(cli): choose proxy agent based on requester protocol (#2521) --- packages/cli/src/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index a026f3604..b965eff60 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -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