mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-13 08:13:00 +02:00
Ability to disable proxy config
Closes https://feedback.yaak.app/p/proxy-save-last-data
This commit is contained in:
@@ -123,7 +123,12 @@ pub async fn send_http_request<R: Runtime>(
|
|||||||
|
|
||||||
match settings.proxy {
|
match settings.proxy {
|
||||||
Some(ProxySetting::Disabled) => client_builder = client_builder.no_proxy(),
|
Some(ProxySetting::Disabled) => client_builder = client_builder.no_proxy(),
|
||||||
Some(ProxySetting::Enabled { http, https, auth }) => {
|
Some(ProxySetting::Enabled {
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
auth,
|
||||||
|
disabled,
|
||||||
|
}) if !disabled => {
|
||||||
debug!("Using proxy http={http} https={https}");
|
debug!("Using proxy http={http} https={https}");
|
||||||
let mut proxy = Proxy::custom(move |url| {
|
let mut proxy = Proxy::custom(move |url| {
|
||||||
let http = if http.is_empty() { None } else { Some(http.to_owned()) };
|
let http = if http.is_empty() { None } else { Some(http.to_owned()) };
|
||||||
@@ -143,7 +148,7 @@ pub async fn send_http_request<R: Runtime>(
|
|||||||
|
|
||||||
client_builder = client_builder.proxy(proxy);
|
client_builder = client_builder.proxy(proxy);
|
||||||
}
|
}
|
||||||
None => {} // Nothing to do for this one, as it is the default
|
_ => {} // Nothing to do for this one, as it is the default
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add cookie store if specified
|
// Add cookie store if specified
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ macro_rules! impl_model {
|
|||||||
#[ts(export, export_to = "gen_models.ts")]
|
#[ts(export, export_to = "gen_models.ts")]
|
||||||
pub enum ProxySetting {
|
pub enum ProxySetting {
|
||||||
Enabled {
|
Enabled {
|
||||||
|
#[serde(default)]
|
||||||
|
// This was added after on so give it a default to be able to deserialize older values
|
||||||
|
disabled: bool,
|
||||||
http: String,
|
http: String,
|
||||||
https: String,
|
https: String,
|
||||||
auth: Option<ProxySettingAuth>,
|
auth: Option<ProxySettingAuth>,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export function SettingsProxy() {
|
|||||||
} else if (v === 'enabled') {
|
} else if (v === 'enabled') {
|
||||||
await patchModel(settings, {
|
await patchModel(settings, {
|
||||||
proxy: {
|
proxy: {
|
||||||
|
disabled: false,
|
||||||
type: 'enabled',
|
type: 'enabled',
|
||||||
http: '',
|
http: '',
|
||||||
https: '',
|
https: '',
|
||||||
@@ -42,16 +43,42 @@ export function SettingsProxy() {
|
|||||||
/>
|
/>
|
||||||
{settings.proxy?.type === 'enabled' && (
|
{settings.proxy?.type === 'enabled' && (
|
||||||
<VStack space={1.5}>
|
<VStack space={1.5}>
|
||||||
<HStack space={1.5} className="mt-3">
|
<Checkbox
|
||||||
|
className="my-3"
|
||||||
|
checked={!settings.proxy.disabled}
|
||||||
|
title="Enable proxy"
|
||||||
|
help="Use this to temporarily disable the proxy without losing the configuration"
|
||||||
|
onChange={async (enabled) => {
|
||||||
|
const { proxy } = settings;
|
||||||
|
const http = proxy?.type === 'enabled' ? proxy.http : '';
|
||||||
|
const https = proxy?.type === 'enabled' ? proxy.https : '';
|
||||||
|
const auth = proxy?.type === 'enabled' ? proxy.auth : null;
|
||||||
|
const disabled = !enabled;
|
||||||
|
await patchModel(settings, {
|
||||||
|
proxy: { type: 'enabled', http, https, auth, disabled },
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<HStack space={1.5}>
|
||||||
<PlainInput
|
<PlainInput
|
||||||
size="sm"
|
size="sm"
|
||||||
label="HTTP"
|
label="HTTP"
|
||||||
placeholder="localhost:9090"
|
placeholder="localhost:9090"
|
||||||
defaultValue={settings.proxy?.http}
|
defaultValue={settings.proxy?.http}
|
||||||
onChange={async (http) => {
|
onChange={async (http) => {
|
||||||
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
|
const { proxy } = settings;
|
||||||
const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null;
|
const https = proxy?.type === 'enabled' ? proxy.https : '';
|
||||||
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
|
const auth = proxy?.type === 'enabled' ? proxy.auth : null;
|
||||||
|
const disabled = proxy?.type === 'enabled' ? proxy.disabled : false;
|
||||||
|
await patchModel(settings, {
|
||||||
|
proxy: {
|
||||||
|
type: 'enabled',
|
||||||
|
http,
|
||||||
|
https,
|
||||||
|
auth,
|
||||||
|
disabled,
|
||||||
|
},
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<PlainInput
|
<PlainInput
|
||||||
@@ -60,9 +87,13 @@ export function SettingsProxy() {
|
|||||||
placeholder="localhost:9090"
|
placeholder="localhost:9090"
|
||||||
defaultValue={settings.proxy?.https}
|
defaultValue={settings.proxy?.https}
|
||||||
onChange={async (https) => {
|
onChange={async (https) => {
|
||||||
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
|
const { proxy } = settings;
|
||||||
const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null;
|
const http = proxy?.type === 'enabled' ? proxy.http : '';
|
||||||
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
|
const auth = proxy?.type === 'enabled' ? proxy.auth : null;
|
||||||
|
const disabled = proxy?.type === 'enabled' ? proxy.disabled : false;
|
||||||
|
await patchModel(settings, {
|
||||||
|
proxy: { type: 'enabled', http, https, auth, disabled },
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
@@ -71,10 +102,14 @@ export function SettingsProxy() {
|
|||||||
checked={settings.proxy.auth != null}
|
checked={settings.proxy.auth != null}
|
||||||
title="Enable authentication"
|
title="Enable authentication"
|
||||||
onChange={async (enabled) => {
|
onChange={async (enabled) => {
|
||||||
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
|
const { proxy } = settings;
|
||||||
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
|
const http = proxy?.type === 'enabled' ? proxy.http : '';
|
||||||
|
const https = proxy?.type === 'enabled' ? proxy.https : '';
|
||||||
|
const disabled = proxy?.type === 'enabled' ? proxy.disabled : false;
|
||||||
const auth = enabled ? { user: '', password: '' } : null;
|
const auth = enabled ? { user: '', password: '' } : null;
|
||||||
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
|
await patchModel(settings, {
|
||||||
|
proxy: { type: 'enabled', http, https, auth, disabled },
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@@ -87,12 +122,15 @@ export function SettingsProxy() {
|
|||||||
placeholder="myUser"
|
placeholder="myUser"
|
||||||
defaultValue={settings.proxy.auth.user}
|
defaultValue={settings.proxy.auth.user}
|
||||||
onChange={async (user) => {
|
onChange={async (user) => {
|
||||||
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
|
const { proxy } = settings;
|
||||||
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
|
const http = proxy?.type === 'enabled' ? proxy.http : '';
|
||||||
const password =
|
const https = proxy?.type === 'enabled' ? proxy.https : '';
|
||||||
settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.password ?? '') : '';
|
const disabled = proxy?.type === 'enabled' ? proxy.disabled : false;
|
||||||
|
const password = proxy?.type === 'enabled' ? (proxy.auth?.password ?? '') : '';
|
||||||
const auth = { user, password };
|
const auth = { user, password };
|
||||||
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
|
await patchModel(settings, {
|
||||||
|
proxy: { type: 'enabled', http, https, auth, disabled },
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<PlainInput
|
<PlainInput
|
||||||
@@ -102,12 +140,15 @@ export function SettingsProxy() {
|
|||||||
placeholder="s3cretPassw0rd"
|
placeholder="s3cretPassw0rd"
|
||||||
defaultValue={settings.proxy.auth.password}
|
defaultValue={settings.proxy.auth.password}
|
||||||
onChange={async (password) => {
|
onChange={async (password) => {
|
||||||
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
|
const { proxy } = settings;
|
||||||
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
|
const http = proxy?.type === 'enabled' ? proxy.http : '';
|
||||||
const user =
|
const https = proxy?.type === 'enabled' ? proxy.https : '';
|
||||||
settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.user ?? '') : '';
|
const disabled = proxy?.type === 'enabled' ? proxy.disabled : false;
|
||||||
|
const user = proxy?.type === 'enabled' ? (proxy.auth?.user ?? '') : '';
|
||||||
const auth = { user, password };
|
const auth = { user, password };
|
||||||
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
|
await patchModel(settings, {
|
||||||
|
proxy: { type: 'enabled', http, https, auth, disabled },
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|||||||
Reference in New Issue
Block a user