From 795fb08d1f3da3cb1b7600b7997ec88ba7607a08 Mon Sep 17 00:00:00 2001 From: lohit-bruno Date: Tue, 3 Mar 2026 09:31:37 +0530 Subject: [PATCH] feat(cli): add --disable-http-https-agents-cache flag --- packages/bruno-cli/src/commands/run.js | 9 +++++++++ .../bruno-cli/src/runner/run-single-request.js | 17 +++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index bf5cc766d..a00f82cd7 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -225,6 +225,11 @@ const builder = async (yargs) => { description: 'Disable all proxy settings (both collection-defined and system proxies)', default: false }) + .option('disable-http-https-agents-cache', { + type: 'boolean', + description: 'Disable HTTP/HTTPS agent caching — creates a fresh agent for every request', + default: false + }) .option('delay', { type: 'number', description: 'Delay between each requests (in miliseconds)' @@ -330,6 +335,7 @@ const handler = async function (argv) { reporterSkipBody, clientCertConfig, noproxy, + disableHttpHttpsAgentsCache, delay, tags: includeTags, excludeTags, @@ -531,6 +537,9 @@ const handler = async function (argv) { if (noproxy) { options['noproxy'] = true; } + if (disableHttpHttpsAgentsCache) { + options['disableHttpHttpsAgentsCache'] = true; + } if (verbose) { options['verbose'] = true; } diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 01923c5c3..213f8fccf 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -348,6 +348,7 @@ const runSingleRequest = async function ( const insecure = get(options, 'insecure', false); const noproxy = get(options, 'noproxy', false); const cachedSystemProxy = get(options, 'cachedSystemProxy', null); + const disableCache = get(options, 'disableHttpHttpsAgentsCache', false); const httpsAgentRequestFields = {}; if (insecure) { @@ -459,15 +460,15 @@ const runSingleRequest = async function ( // Only set the agent needed for the request protocol if (socksEnabled) { if (isHttpsRequest) { - request.httpsAgent = getOrCreateAgent({ AgentClass: SocksProxyAgent, options: tlsOptions, proxyUri }); + request.httpsAgent = getOrCreateAgent({ AgentClass: SocksProxyAgent, options: tlsOptions, proxyUri, disableCache }); } else { - request.httpAgent = getOrCreateHttpAgent({ AgentClass: SocksProxyAgent, options: httpAgentOptions, proxyUri }); + request.httpAgent = getOrCreateHttpAgent({ AgentClass: SocksProxyAgent, options: httpAgentOptions, proxyUri, disableCache }); } } else { if (isHttpsRequest) { - request.httpsAgent = getOrCreateAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri }); + request.httpsAgent = getOrCreateAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri, disableCache }); } else { - request.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpAgentOptions, proxyUri }); + request.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpAgentOptions, proxyUri, disableCache }); } } } @@ -479,7 +480,7 @@ const runSingleRequest = async function ( try { if (http_proxy?.length && !isHttpsRequest) { new URL(http_proxy); - request.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpAgentOptions, proxyUri: http_proxy }); + request.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpAgentOptions, proxyUri: http_proxy, disableCache }); } } catch (error) { throw new Error('Invalid system http_proxy'); @@ -487,7 +488,7 @@ const runSingleRequest = async function ( try { if (https_proxy?.length && isHttpsRequest) { new URL(https_proxy); - request.httpsAgent = getOrCreateAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri: https_proxy }); + request.httpsAgent = getOrCreateAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri: https_proxy, disableCache }); } } catch (error) { throw new Error('Invalid system https_proxy'); @@ -501,9 +502,9 @@ const runSingleRequest = async function ( if (!request.httpAgent && !request.httpsAgent) { if (isHttpsRequest) { - request.httpsAgent = getOrCreateAgent({ AgentClass: https.Agent, options: tlsOptions }); + request.httpsAgent = getOrCreateAgent({ AgentClass: https.Agent, options: tlsOptions, disableCache }); } else { - request.httpAgent = getOrCreateHttpAgent({ AgentClass: http.Agent, options: httpAgentOptions }); + request.httpAgent = getOrCreateHttpAgent({ AgentClass: http.Agent, options: httpAgentOptions, disableCache }); } }