chore: add support for cli

This commit is contained in:
Ricardo Q. Bazan
2023-10-08 12:09:33 -05:00
parent ce2e997c06
commit bf90ee96e5
3 changed files with 22 additions and 9 deletions

View File

@@ -13,6 +13,7 @@ const { getOptions } = require('../utils/bru');
const https = require('https');
const { HttpsProxyAgent } = require('https-proxy-agent');
const { HttpProxyAgent } = require('http-proxy-agent');
const { SocksProxyAgent } = require('socks-proxy-agent');
const { makeAxiosInstance } = require('../utils/axios-instance');
const runSingleRequest = async function (
@@ -96,7 +97,7 @@ const runSingleRequest = async function (
// set proxy if enabled
const proxyEnabled = get(brunoConfig, 'proxy.enabled', false);
if (proxyEnabled) {
let proxy;
let proxyUri;
const interpolationOptions = {
envVars: envVariables,
collectionVariables,
@@ -107,6 +108,7 @@ const runSingleRequest = async function (
const proxyHostname = interpolateString(get(brunoConfig, 'proxy.hostname'), interpolationOptions);
const proxyPort = interpolateString(get(brunoConfig, 'proxy.port'), interpolationOptions);
const proxyAuthEnabled = get(brunoConfig, 'proxy.auth.enabled', false);
const socksEnabled = proxyProtocol.includes('socks');
interpolateString;
@@ -114,17 +116,25 @@ const runSingleRequest = async function (
const proxyAuthUsername = interpolateString(get(brunoConfig, 'proxy.auth.username'), interpolationOptions);
const proxyAuthPassword = interpolateString(get(brunoConfig, 'proxy.auth.password'), interpolationOptions);
proxy = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`;
proxyUri = `${proxyProtocol}://${proxyAuthUsername}:${proxyAuthPassword}@${proxyHostname}:${proxyPort}`;
} else {
proxy = `${proxyProtocol}://${proxyHostname}:${proxyPort}`;
proxyUri = `${proxyProtocol}://${proxyHostname}:${proxyPort}`;
}
request.httpsAgent = new HttpsProxyAgent(
proxy,
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
);
if (socksEnabled) {
const socksProxyAgent = new SocksProxyAgent(proxyUri);
request.httpAgent = new HttpProxyAgent(proxy);
request.httpsAgent = socksProxyAgent;
request.httpAgent = socksProxyAgent;
} else {
request.httpsAgent = new HttpsProxyAgent(
proxyUri,
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
);
request.httpAgent = new HttpProxyAgent(proxyUri);
}
} else if (Object.keys(httpsAgentRequestFields).length > 0) {
request.httpsAgent = new https.Agent({
...httpsAgentRequestFields