diff --git a/api/utils/countly-request/index.js b/api/utils/countly-request/index.js index 1e16659cba3..142dff308d9 100755 --- a/api/utils/countly-request/index.js +++ b/api/utils/countly-request/index.js @@ -39,34 +39,40 @@ var initParams = function(uri, options, callback) { params.options = {}; // Create options object if it's undefined } - const proxyType = config.proxy_type || "https"; - const proxyUrlBase = `${proxyType}://${config.proxy_hostname}:${config.proxy_port}`; + let proxyUrl; + const hasCredentials = config.proxy_username && config.proxy_password; + const protocol = config.proxy_hostname.startsWith("https://") ? "https://" : "http://"; + const credentials = hasCredentials ? `${config.proxy_username}:${config.proxy_password}@` : ""; - let proxyUrl = proxyUrlBase; + let proxyHostName = config.proxy_hostname.replace(protocol, ""); - if (config.proxy_username && config.proxy_password) { - proxyUrl = `${proxyType}://${config.proxy_username}:${config.proxy_password}@${config.proxy_hostname}:${config.proxy_port}`; + if (hasCredentials) { + proxyUrl = `${protocol}${credentials}${proxyHostName}:${config.proxy_port}`; } + else { + proxyUrl = `${protocol}${proxyHostName}:${config.proxy_port}`; + } + + // Determine the target URL from the available options + const targetUrl = params.uri || params.options.url || params.options.uri; + + // Check if the target URL uses HTTPS + const isHttps = targetUrl.startsWith('https'); + // Define common agent options const agentOptions = { keepAlive: true, keepAliveMsecs: 1000, maxSockets: 256, maxFreeSockets: 256, scheduling: 'lifo', - proxy: proxyUrl, + proxy: proxyUrl, // Set the proxy URL }; - if (proxyType === "https") { - params.options.agent = { - https: new HttpsProxyAgent(agentOptions) - }; - } - else { - params.options.agent = { - http: new HttpProxyAgent(agentOptions) - }; - } + params.options.agent = isHttps ? + { https: new HttpsProxyAgent(agentOptions) } : + { https: new HttpProxyAgent(agentOptions) }; + } return params; diff --git a/plugins/plugins/frontend/public/javascripts/countly.views.js b/plugins/plugins/frontend/public/javascripts/countly.views.js index 8bed65bedc5..6407f6e8b4d 100644 --- a/plugins/plugins/frontend/public/javascripts/countly.views.js +++ b/plugins/plugins/frontend/public/javascripts/countly.views.js @@ -1133,16 +1133,6 @@ app.configurationsView.registerInput("security.proxy_password", {input: "el-input", attrs: {type: "textarea", rows: 1}}); - app.configurationsView.registerInput("security.proxy_type", { - input: "el-select", - attrs: {}, - list: [ - {value: 'https', label: 'https'}, - {value: 'http', label: 'http'} - ] - }); - - app.configurationsView.registerInput("api.reports_regenerate_interval", { input: "el-select", attrs: {},