Skip to content

Commit

Permalink
Merge pull request #4962 from Countly/SER-1147-proxy-bugfix
Browse files Browse the repository at this point in the history
[SER-1147] proxy agent bugfix
  • Loading branch information
ar2rsawseen authored Mar 7, 2024
2 parents 55ec921 + 73e4079 commit 8b127d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
38 changes: 22 additions & 16 deletions api/utils/countly-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions plugins/plugins/frontend/public/javascripts/countly.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down

0 comments on commit 8b127d8

Please sign in to comment.