From f5018e9820ef12cfe257a77430cd3d07f75888c2 Mon Sep 17 00:00:00 2001 From: zadam Date: Mon, 20 Nov 2023 23:03:19 +0100 Subject: [PATCH] fix buggy http proxy initialization, closes #4453 --- src/services/request.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/services/request.js b/src/services/request.js index 0af02b7ea..5a7158007 100644 --- a/src/services/request.js +++ b/src/services/request.js @@ -160,6 +160,8 @@ function getImage(imageUrl) { }); } +const HTTP = 'http:', HTTPS = 'https:'; + function getProxyAgent(opts) { if (!opts.proxy) { return null; @@ -167,15 +169,15 @@ function getProxyAgent(opts) { const {protocol} = url.parse(opts.url); - if (protocol === 'http:' || protocol === 'https:') { - const protoNoColon = protocol.substr(0, protocol.length - 1); - const AgentClass = require(`${protoNoColon}-proxy-agent`); - - return new AgentClass(opts.proxy); - } - else { + if (![HTTP, HTTPS].includes(protocol)) { return null; } + + const AgentClass = HTTP === protocol + ? require("http-proxy-agent").HttpProxyAgent + : require("https-proxy-agent").HttpsProxyAgent; + + return new AgentClass(opts.proxy); } function getClient(opts) {