From 1b3676dd1bef5b34eb8436feb746cc9952087718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Wed, 2 Aug 2023 15:38:59 +0200 Subject: [PATCH] fix(cli): choose proxy agent based on requester protocol --- 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