Added proxy flag for cli (#3963)

* system level proxy depends on proxy flag

* added proxy flag

* fix: proxy flag behaviour

* fix: noproxy flag logic
This commit is contained in:
naman-bruno
2025-05-16 14:02:11 +05:30
committed by GitHub
parent 79f4e69a05
commit 9f044c48fe
2 changed files with 24 additions and 8 deletions

View File

@@ -164,6 +164,11 @@ const builder = async (yargs) => {
type: 'string',
description: 'Path to the Client certificate config file used for securing the connection in the request'
})
.option('--noproxy', {
type: 'boolean',
description: 'Disable all proxy settings (both collection-defined and system proxies)',
default: false
})
.option('delay', {
type:"number",
description: "Delay between each requests (in miliseconds)"
@@ -197,7 +202,6 @@ const builder = async (yargs) => {
'$0 run request.bru --reporter-junit results.xml --reporter-html results.html',
'Run a request and write the results to results.html in html format and results.xml in junit format in the current directory'
)
.example('$0 run request.bru --tests-only', 'Run all requests that have a test')
.example(
'$0 run request.bru --cacert myCustomCA.pem',
@@ -208,7 +212,8 @@ const builder = async (yargs) => {
'Use a custom CA certificate exclusively when validating the peers of the requests in the specified folder.'
)
.example('$0 run --client-cert-config client-cert-config.json', 'Run a request with Client certificate configurations')
.example('$0 run folder --delay delayInMs', 'Run a folder with given miliseconds delay between each requests.');
.example('$0 run folder --delay delayInMs', 'Run a folder with given miliseconds delay between each requests.')
.example('$0 run --noproxy', 'Run requests with system proxy disabled');
};
const handler = async function (argv) {
@@ -233,6 +238,7 @@ const handler = async function (argv) {
reporterSkipAllHeaders,
reporterSkipHeaders,
clientCertConfig,
noproxy,
delay
} = argv;
const collectionPath = process.cwd();
@@ -451,7 +457,8 @@ const handler = async function (argv) {
collectionRoot,
runtime,
collection,
runSingleRequestByPathname
runSingleRequestByPathname,
noproxy
);
resolve(res?.response);
}
@@ -476,7 +483,8 @@ const handler = async function (argv) {
collectionRoot,
runtime,
collection,
runSingleRequestByPathname
runSingleRequestByPathname,
noproxy
);
const isLastRun = currentRequestIndex === requestItems.length - 1;

View File

@@ -41,7 +41,8 @@ const runSingleRequest = async function (
collectionRoot,
runtime,
collection,
runSingleRequestByPathname
runSingleRequestByPathname,
noproxy
) {
const { pathname: itemPathname } = item;
const relativeItemPathname = path.relative(collectionPath, itemPathname);
@@ -179,15 +180,22 @@ const runSingleRequest = async function (
const collectionProxyConfig = get(brunoConfig, 'proxy', {});
const collectionProxyEnabled = get(collectionProxyConfig, 'enabled', false);
if (collectionProxyEnabled === true) {
if (noproxy) {
// If noproxy flag is set, don't use any proxy
proxyMode = 'off';
} else if (collectionProxyEnabled === true) {
// If collection proxy is enabled, use it
proxyConfig = collectionProxyConfig;
proxyMode = 'on';
} else {
// if the collection level proxy is not set, pick the system level proxy by default, to maintain backward compatibility
} else if (collectionProxyEnabled === 'global') {
// If collection proxy is set to 'global', use system proxy
const { http_proxy, https_proxy } = getSystemProxyEnvVariables();
if (http_proxy?.length || https_proxy?.length) {
proxyMode = 'system';
}
} else {
proxyMode = 'off';
}
if (proxyMode === 'on') {