feat(bruno-requests): integrate agent cache into http-https-agents

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
lohit-bruno
2026-01-29 16:35:46 +05:30
parent f51a7b2ded
commit 9df4b04ae8
2 changed files with 23 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ export { default as createVaultClient, VaultError } from './utils/node-vault';
export type { VaultClient, VaultConfig, VaultRequestOptions } from './utils/node-vault';
export { getHttpHttpsAgents } from './utils/http-https-agents';
export { initializeShellEnv } from './utils/shell-env';
export { getOrCreateAgent, clearAgentCache, getAgentCacheSize } from './utils/agent-cache';
export * as scripting from './scripting';

View File

@@ -10,6 +10,7 @@ import { HttpProxyAgent } from 'http-proxy-agent';
import { isEmpty, get, isUndefined, isNull } from 'lodash';
import { getCACertificates } from './ca-cert';
import { transformProxyConfig } from './proxy-util';
import { getOrCreateAgent } from './agent-cache';
const DEFAULT_PORTS: Record<string, number> = {
ftp: 21,
@@ -113,6 +114,12 @@ type GetCertsAndProxyConfigResult = {
certsConfig: CertsConfig;
};
type TimelineEntry = {
timestamp: Date;
type: 'info' | 'tls' | 'error';
message: string;
};
type CreateAgentsParams = {
requestUrl?: string;
proxyMode: ProxyMode;
@@ -120,6 +127,7 @@ type CreateAgentsParams = {
certsConfig: CertsConfig;
httpsAgentRequestFields: HttpsAgentRequestFields;
systemProxyConfig?: SystemProxyConfig;
timeline?: TimelineEntry[];
};
type GetHttpHttpsAgentsParams = {
@@ -132,6 +140,7 @@ type GetHttpHttpsAgentsParams = {
collectionLevelProxy?: ProxyConfig;
appLevelProxyConfig?: Record<string, any>;
systemProxyConfig?: SystemProxyConfig;
timeline?: TimelineEntry[];
};
/**
@@ -342,7 +351,8 @@ function createAgents({
proxyConfig,
systemProxyConfig,
certsConfig,
httpsAgentRequestFields
httpsAgentRequestFields,
timeline
}: CreateAgentsParams): AgentResult {
// Ensure TLS options are properly set
const tlsOptions: TlsOptions = {
@@ -383,14 +393,14 @@ function createAgents({
if (socksEnabled) {
httpAgent = new SocksProxyAgent(proxyUri);
httpsAgent = new SocksProxyAgent(proxyUri, tlsOptions as any);
httpsAgent = getOrCreateAgent(SocksProxyAgent, tlsOptions as any, proxyUri, timeline || null) as HttpsAgent;
} else {
httpAgent = new HttpProxyAgent(proxyUri);
httpsAgent = new PatchedHttpsProxyAgent(proxyUri, tlsOptions);
httpsAgent = getOrCreateAgent(PatchedHttpsProxyAgent, tlsOptions as any, proxyUri, timeline || null) as HttpsAgent;
}
} else {
// If proxy should not be used, set default HTTPS agent
httpsAgent = new https.Agent(tlsOptions as any);
httpsAgent = getOrCreateAgent(https.Agent, tlsOptions as any, null, timeline || null) as HttpsAgent;
}
} else if (proxyMode === 'system') {
const http_proxy = get(systemProxyConfig, 'http_proxy');
@@ -409,18 +419,18 @@ function createAgents({
try {
if (https_proxy?.length) {
new URL(https_proxy);
httpsAgent = new PatchedHttpsProxyAgent(https_proxy, tlsOptions as any);
httpsAgent = getOrCreateAgent(PatchedHttpsProxyAgent, tlsOptions as any, https_proxy, timeline || null) as HttpsAgent;
} else {
httpsAgent = new https.Agent(tlsOptions as any);
httpsAgent = getOrCreateAgent(https.Agent, tlsOptions as any, null, timeline || null) as HttpsAgent;
}
} catch (error) {
throw new Error('Invalid system https_proxy');
}
} else {
httpsAgent = new https.Agent(tlsOptions as any);
httpsAgent = getOrCreateAgent(https.Agent, tlsOptions as any, null, timeline || null) as HttpsAgent;
}
} else {
httpsAgent = new https.Agent(tlsOptions as any);
httpsAgent = getOrCreateAgent(https.Agent, tlsOptions as any, null, timeline || null) as HttpsAgent;
}
return { httpAgent, httpsAgent };
@@ -433,7 +443,8 @@ const getHttpHttpsAgents = async ({
collectionLevelProxy,
appLevelProxyConfig,
systemProxyConfig,
options
options,
timeline
}: GetHttpHttpsAgentsParams): Promise<AgentResult> => {
const { proxyMode, proxyConfig, certsConfig } = getCertsAndProxyConfig({
requestUrl,
@@ -460,7 +471,8 @@ const getHttpHttpsAgents = async ({
proxyConfig,
systemProxyConfig,
certsConfig,
httpsAgentRequestFields
httpsAgentRequestFields,
timeline
});
return { httpAgent, httpsAgent };