Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/bruno-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"decomment": "^0.9.5",
"form-data": "4.0.6",
"fs-extra": "^10.1.0",
"http-proxy-agent": "^7.0.0",
"https-proxy-agent": "^7.0.2",
"iconv-lite": "^0.6.3",
"js-yaml": "4.3.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/bruno-cli/src/utils/proxy-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ const parseUrl = require('url').parse;
const http = require('node:http');
const https = require('node:https');
const { isEmpty, get, isUndefined, isNull } = require('lodash');
const { HttpProxyAgent } = require('http-proxy-agent');
const { SocksProxyAgent } = require('socks-proxy-agent');
const {
getOrCreateHttpsAgent,
getOrCreateHttpAgent,
resolveAgentsFromPac,
PatchedHttpsProxyAgent
PatchedHttpsProxyAgent,
HeaderSafeHttpProxyAgent
} = require('@usebruno/requests');
const { interpolateString } = require('../runner/interpolate-string');

Expand Down Expand Up @@ -129,7 +129,7 @@ async function setupProxyAgents({
if (isHttpsRequest) {
requestConfig.httpsAgent = getOrCreateHttpsAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri, disableCache, hostname });
} else {
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpProxyAgentOptions, proxyUri, disableCache, hostname });
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HeaderSafeHttpProxyAgent, options: httpProxyAgentOptions, proxyUri, disableCache, hostname });
}
}
}
Expand All @@ -152,7 +152,7 @@ async function setupProxyAgents({
const parsedHttpProxy = new URL(http_proxy);
const isHttpsSystemProxy = parsedHttpProxy.protocol === 'https:';
const systemHttpProxyAgentOptions = isHttpsSystemProxy ? { ...httpAgentOptions, ...tlsOptions } : httpAgentOptions;
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: systemHttpProxyAgentOptions, proxyUri: http_proxy, disableCache, hostname });
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HeaderSafeHttpProxyAgent, options: systemHttpProxyAgentOptions, proxyUri: http_proxy, disableCache, hostname });
}
} catch (error) {
throw new Error('Invalid system http_proxy');
Expand Down
38 changes: 38 additions & 0 deletions packages/bruno-cli/tests/utils/proxy-util.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { describe, it, expect, beforeEach } = require('@jest/globals');

jest.mock('@usebruno/requests', () => ({
getOrCreateHttpsAgent: jest.fn(() => ({ type: 'https-agent' })),
getOrCreateHttpAgent: jest.fn(() => ({ type: 'http-agent' })),
resolveAgentsFromPac: jest.fn(),
PatchedHttpsProxyAgent: class {},
HeaderSafeHttpProxyAgent: class {}
}));

const { getOrCreateHttpAgent, HeaderSafeHttpProxyAgent } = require('@usebruno/requests');
const { setupProxyAgents } = require('../../src/utils/proxy-util');

describe('setupProxyAgents', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it.each([
['on', { proxyConfig: { protocol: 'http', hostname: 'p.example', port: '8080', auth: { disabled: true } } }],
['system', { systemProxyConfig: { http_proxy: 'http://p.example:8080' } }]
])('%s mode uses HeaderSafeHttpProxyAgent for http requests', async (proxyMode, proxySettings) => {
const requestConfig = { url: 'http://example.com/resource' };

await setupProxyAgents({
requestConfig,
proxyMode,
...proxySettings,
httpsAgentRequestFields: {},
interpolationOptions: {}
});

expect(requestConfig.httpAgent).toBeDefined();
expect(getOrCreateHttpAgent).toHaveBeenCalledWith(
expect.objectContaining({ AgentClass: HeaderSafeHttpProxyAgent, proxyUri: 'http://p.example:8080' })
);
});
});
1 change: 0 additions & 1 deletion packages/bruno-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"form-data": "4.0.6",
"fs-extra": "^10.1.0",
"graphql": "^16.6.0",
"http-proxy-agent": "^7.0.0",
"iconv-lite": "^0.6.3",
"is-valid-path": "^0.1.1",
"js-yaml": "4.3.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/bruno-electron/src/utils/proxy-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const https = require('node:https');
const http = require('node:http');
const { interpolateString } = require('../ipc/network/interpolate-string');
const { SocksProxyAgent } = require('socks-proxy-agent');
const { HttpProxyAgent } = require('http-proxy-agent');
const { isEmpty, get, isUndefined, isNull } = require('lodash');
const {
getOrCreateHttpsAgent,
getOrCreateHttpAgent,
resolveAgentsFromPac,
PatchedHttpsProxyAgent
PatchedHttpsProxyAgent,
HeaderSafeHttpProxyAgent
} = require('@usebruno/requests');
const { preferencesUtil } = require('../store/preferences');

Expand Down Expand Up @@ -150,7 +150,7 @@ async function setupProxyAgents({
if (isHttpsRequest) {
requestConfig.httpsAgent = getOrCreateHttpsAgent({ AgentClass: PatchedHttpsProxyAgent, options: tlsOptions, proxyUri, timeline, disableCache, hostname });
} else {
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: httpProxyAgentOptions, proxyUri, timeline, disableCache, hostname });
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HeaderSafeHttpProxyAgent, options: httpProxyAgentOptions, proxyUri, timeline, disableCache, hostname });
}
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ async function setupProxyAgents({
message: `Using system proxy: ${http_proxy}`
});
}
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HttpProxyAgent, options: systemHttpProxyAgentOptions, proxyUri: http_proxy, timeline, disableCache, hostname });
requestConfig.httpAgent = getOrCreateHttpAgent({ AgentClass: HeaderSafeHttpProxyAgent, options: systemHttpProxyAgentOptions, proxyUri: http_proxy, timeline, disableCache, hostname });
}
} catch (error) {
throw new Error(`Invalid system http_proxy "${http_proxy}": ${error.message}`);
Expand Down
27 changes: 27 additions & 0 deletions packages/bruno-electron/test/proxy-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const setupMocks = ({ pacDirectives = ['PROXY p.example:8080'] } = {}) => {
getPacResolver,
resolveAgentsFromPac,
PatchedHttpsProxyAgent: class {},
HeaderSafeHttpProxyAgent: class {},
clearPacCache: jest.fn()
};
});
Expand Down Expand Up @@ -147,6 +148,31 @@ describe('proxy-util', () => {
);
});

test.each([
['on', { protocol: 'http', hostname: 'p.example', port: '8080', auth: { disabled: true } }],
['system', { http_proxy: 'http://p.example:8080' }]
])('setupProxyAgents: %s mode uses HeaderSafeHttpProxyAgent for http requests', async (proxyMode, proxyConfig) => {
setupMocks();
const { setupProxyAgents } = require('../src/utils/proxy-util');
const { getOrCreateHttpAgent, HeaderSafeHttpProxyAgent } = require('@usebruno/requests');

const requestConfig = { url: 'http://example.com/resource' };

await setupProxyAgents({
requestConfig,
proxyMode,
proxyConfig,
httpsAgentRequestFields: {},
interpolationOptions: {},
timeline: []
});

expect(requestConfig.httpAgent).toBeDefined();
expect(getOrCreateHttpAgent).toHaveBeenCalledWith(
expect.objectContaining({ AgentClass: HeaderSafeHttpProxyAgent, proxyUri: 'http://p.example:8080' })
);
});

test('setupProxyAgents: PAC resolution error logs to timeline and falls back to direct agent', async () => {
jest.doMock('../src/store/preferences', () => ({
preferencesUtil: { isSslSessionCachingEnabled: () => false }
Expand All @@ -157,6 +183,7 @@ describe('proxy-util', () => {
getPacResolver: jest.fn(async () => { throw new Error('PAC fetch timeout'); }),
resolveAgentsFromPac: jest.fn(async () => { throw new Error('PAC fetch timeout'); }),
PatchedHttpsProxyAgent: class {},
HeaderSafeHttpProxyAgent: class {},
clearPacCache: jest.fn()
}));

Expand Down
1 change: 1 addition & 0 deletions packages/bruno-requests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@types/jest": "^29.5.11",
"babel-jest": "^29.7.0",
"builtin-modules": "^5.0.0",
"form-data": "4.0.6",
"jest": "^29.2.0",
"rollup": "3.30.0",
"rollup-plugin-dts": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-requests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export { getCACertificates } from './utils/ca-cert';
export { transformProxyConfig } from './utils/proxy-util';
export { default as createVaultClient, VaultError } from './utils/node-vault';
export type { VaultClient, VaultConfig, VaultRequestOptions } from './utils/node-vault';
export { getHttpHttpsAgents, resolveAgentsFromPac, PatchedHttpsProxyAgent } from './utils/http-https-agents';
export { getHttpHttpsAgents, resolveAgentsFromPac, PatchedHttpsProxyAgent, HeaderSafeHttpProxyAgent } from './utils/http-https-agents';
export { initializeShellEnv, fetchShellEnv } from './utils/shell-env';
export { getOrCreateHttpsAgent, getOrCreateHttpAgent, clearAgentCache, getAgentCacheSize } from './utils/agent-cache';
export { configureHybridTlsDefaults } from './utils/hybrid-key-exchange';
Expand Down
Loading
Loading