feat(bruno-cli): use agent cache for SSL session reuse

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
lohit-bruno
2026-01-29 16:36:07 +05:30
parent dbc1d11e23
commit c2bad2e2c8

View File

@@ -426,6 +426,12 @@ const runSingleRequest = async function (
} }
// else: collection proxy is disabled, proxyMode stays 'off' // else: collection proxy is disabled, proxyMode stays 'off'
// Prepare TLS options for agent caching
const tlsOptions = {
...httpsAgentRequestFields,
keepAlive: true
};
if (proxyMode === 'on') { if (proxyMode === 'on') {
const shouldProxy = shouldUseProxy(request.url, get(proxyConfig, 'bypassProxy', '')); const shouldProxy = shouldUseProxy(request.url, get(proxyConfig, 'bypassProxy', ''));
if (shouldProxy) { if (shouldProxy) {
@@ -445,22 +451,14 @@ const runSingleRequest = async function (
proxyUri = `${proxyProtocol}://${proxyHostname}${uriPort}`; proxyUri = `${proxyProtocol}://${proxyHostname}${uriPort}`;
} }
if (socksEnabled) { if (socksEnabled) {
request.httpsAgent = new SocksProxyAgent( request.httpAgent = getOrCreateAgent(SocksProxyAgent, { keepAlive: true }, proxyUri);
proxyUri, request.httpsAgent = getOrCreateAgent(SocksProxyAgent, tlsOptions, proxyUri);
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
);
request.httpAgent = new SocksProxyAgent(proxyUri);
} else { } else {
request.httpsAgent = new PatchedHttpsProxyAgent( request.httpAgent = getOrCreateAgent(HttpProxyAgent, { keepAlive: true }, proxyUri);
proxyUri, request.httpsAgent = getOrCreateAgent(PatchedHttpsProxyAgent, tlsOptions, proxyUri);
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined
);
request.httpAgent = new HttpProxyAgent(proxyUri);
} }
} else { } else {
request.httpsAgent = new https.Agent({ request.httpsAgent = getOrCreateAgent(https.Agent, tlsOptions);
...httpsAgentRequestFields
});
} }
} else if (proxyMode === 'system') { } else if (proxyMode === 'system') {
try { try {
@@ -472,7 +470,7 @@ const runSingleRequest = async function (
try { try {
if (http_proxy?.length && !isHttpsRequest) { if (http_proxy?.length && !isHttpsRequest) {
new URL(http_proxy); new URL(http_proxy);
request.httpAgent = new HttpProxyAgent(http_proxy); request.httpAgent = getOrCreateAgent(HttpProxyAgent, { keepAlive: true }, http_proxy);
} }
} catch (error) { } catch (error) {
throw new Error('Invalid system http_proxy'); throw new Error('Invalid system http_proxy');
@@ -480,12 +478,9 @@ const runSingleRequest = async function (
try { try {
if (https_proxy?.length && isHttpsRequest) { if (https_proxy?.length && isHttpsRequest) {
new URL(https_proxy); new URL(https_proxy);
request.httpsAgent = new PatchedHttpsProxyAgent(https_proxy, request.httpsAgent = getOrCreateAgent(PatchedHttpsProxyAgent, tlsOptions, https_proxy);
Object.keys(httpsAgentRequestFields).length > 0 ? { ...httpsAgentRequestFields } : undefined);
} else { } else {
request.httpsAgent = new https.Agent({ request.httpsAgent = getOrCreateAgent(https.Agent, tlsOptions);
...httpsAgentRequestFields
});
} }
} catch (error) { } catch (error) {
throw new Error('Invalid system https_proxy'); throw new Error('Invalid system https_proxy');
@@ -496,14 +491,10 @@ const runSingleRequest = async function (
}); });
} }
} catch (error) { } catch (error) {
request.httpsAgent = new https.Agent({ request.httpsAgent = getOrCreateAgent(https.Agent, tlsOptions);
...httpsAgentRequestFields
});
} }
} else if (Object.keys(httpsAgentRequestFields).length > 0) { } else if (Object.keys(httpsAgentRequestFields).length > 0) {
request.httpsAgent = new https.Agent({ request.httpsAgent = getOrCreateAgent(https.Agent, tlsOptions);
...httpsAgentRequestFields
});
} }
// set cookies if enabled // set cookies if enabled