mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 14:08:38 +00:00
feat: update proxy implementation in preferences
This commit is contained in:
@@ -165,17 +165,32 @@ const configureRequest = async (
|
||||
}
|
||||
}
|
||||
|
||||
// proxy configuration
|
||||
let proxyConfig = get(brunoConfig, 'proxy', {});
|
||||
let proxyMode = get(proxyConfig, 'enabled', 'global');
|
||||
if (proxyMode === 'global') {
|
||||
/**
|
||||
* Proxy configuration
|
||||
*
|
||||
* Preferences proxyMode has three possible values: on, off, system
|
||||
* Collection proxyMode has three possible values: true, false, global
|
||||
*
|
||||
* When collection proxyMode is true, it overrides the app-level proxy settings
|
||||
* When collection proxyMode is false, it ignores the app-level proxy settings
|
||||
* When collection proxyMode is global, it uses the app-level proxy settings
|
||||
*
|
||||
* Below logic calculates the proxyMode and proxyConfig to be used for the request
|
||||
*/
|
||||
let proxyMode = 'off';
|
||||
let proxyConfig = {};
|
||||
|
||||
const collectionProxyConfig = get(brunoConfig, 'proxy', {});
|
||||
const collectionProxyEnabled = get(collectionProxyConfig, 'enabled', 'global');
|
||||
if (collectionProxyEnabled === true) {
|
||||
proxyConfig = collectionProxyConfig;
|
||||
proxyMode = 'on';
|
||||
} else if (collectionProxyEnabled === 'global') {
|
||||
proxyConfig = preferencesUtil.getGlobalProxyConfig();
|
||||
proxyMode = get(proxyConfig, 'mode', false);
|
||||
proxyMode = get(proxyConfig, 'mode', 'off');
|
||||
}
|
||||
|
||||
// proxyMode is true, if the collection-level proxy is enabled.
|
||||
// proxyMode is 'on', if the app-level proxy mode is turned on.
|
||||
if (proxyMode === true || proxyMode === 'on') {
|
||||
if (proxyMode === 'on') {
|
||||
const shouldProxy = shouldUseProxy(request.url, get(proxyConfig, 'bypassProxy', ''));
|
||||
if (shouldProxy) {
|
||||
const proxyProtocol = interpolateString(get(proxyConfig, 'protocol'), interpolationOptions);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Yup = require('yup');
|
||||
const Store = require('electron-store');
|
||||
const { get } = require('lodash');
|
||||
const { get, merge } = require('lodash');
|
||||
|
||||
/**
|
||||
* The preferences are stored in the electron store 'preferences.json'.
|
||||
@@ -81,10 +81,22 @@ class PreferencesStore {
|
||||
}
|
||||
|
||||
getPreferences() {
|
||||
return {
|
||||
...defaultPreferences,
|
||||
...this.store.get('preferences')
|
||||
};
|
||||
let preferences = this.store.get('preferences', {});
|
||||
|
||||
// This to support the old preferences format
|
||||
// In the old format, we had a proxy.enabled flag
|
||||
// In the new format, this maps to proxy.mode = 'on'
|
||||
if (preferences?.proxy?.enabled) {
|
||||
preferences.proxy.mode = 'on';
|
||||
}
|
||||
|
||||
// Delete the proxy.enabled property if it exists, regardless of its value
|
||||
// This is a part of migration to the new preferences format
|
||||
if (preferences?.proxy && 'enabled' in preferences.proxy) {
|
||||
delete preferences.proxy.enabled;
|
||||
}
|
||||
|
||||
return merge({}, defaultPreferences, preferences);
|
||||
}
|
||||
|
||||
savePreferences(newPreferences) {
|
||||
|
||||
Reference in New Issue
Block a user