feat(updater): add no_proxy config to disable system proxy (#3073)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Fabian-Lars <github@fabianlars.de>
This commit is contained in:
miaoshengkun
2026-01-19 23:17:37 +08:00
committed by GitHub
parent 82fbb0c790
commit 4375c98bed
2 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"updater": minor
"updater-js": minor
---
Add no_proxy config to disable system proxy for updater plugin.

View File

@@ -146,6 +146,7 @@ pub struct UpdaterBuilder {
headers: HeaderMap,
timeout: Option<Duration>,
proxy: Option<Url>,
no_proxy: bool,
installer_args: Vec<OsString>,
current_exe_args: Vec<OsString>,
on_before_exit: Option<OnBeforeExit>,
@@ -174,6 +175,7 @@ impl UpdaterBuilder {
headers: Default::default(),
timeout: None,
proxy: None,
no_proxy: false,
on_before_exit: None,
configure_client: None,
}
@@ -242,6 +244,12 @@ impl UpdaterBuilder {
self
}
/// Clear all proxies. See [`reqwest::ClientBuilder::no_proxy`](https://docs.rs/reqwest/latest/reqwest/struct.ClientBuilder.html#method.no_proxy).
pub fn no_proxy(mut self) -> Self {
self.no_proxy = true;
self
}
pub fn pubkey<S: Into<String>>(mut self, pubkey: S) -> Self {
self.config.pubkey = pubkey.into();
self
@@ -323,6 +331,7 @@ impl UpdaterBuilder {
version_comparator: self.version_comparator,
timeout: self.timeout,
proxy: self.proxy,
no_proxy: self.no_proxy,
endpoints,
installer_args: self.installer_args,
current_exe_args: self.current_exe_args,
@@ -357,6 +366,7 @@ pub struct Updater {
version_comparator: Option<VersionComparator>,
timeout: Option<Duration>,
proxy: Option<Url>,
no_proxy: bool,
endpoints: Vec<Url>,
arch: &'static str,
// The `{{target}}` variable we replace in the endpoint and serach for in the JSON,
@@ -448,7 +458,10 @@ impl Updater {
if let Some(timeout) = self.timeout {
request = request.timeout(timeout);
}
if let Some(ref proxy) = self.proxy {
if self.no_proxy {
log::debug!("disabling proxy");
request = request.no_proxy();
} else if let Some(ref proxy) = self.proxy {
log::debug!("using proxy {proxy}");
let proxy = reqwest::Proxy::all(proxy.as_str())?;
request = request.proxy(proxy);
@@ -539,6 +552,7 @@ impl Updater {
raw_json: raw_json.unwrap(),
timeout: None,
proxy: self.proxy.clone(),
no_proxy: self.no_proxy,
headers: self.headers.clone(),
installer_args: self.installer_args.clone(),
current_exe_args: self.current_exe_args.clone(),
@@ -612,6 +626,8 @@ pub struct Update {
pub timeout: Option<Duration>,
/// Request proxy
pub proxy: Option<Url>,
/// Disable system proxy
pub no_proxy: bool,
/// Request headers
pub headers: HeaderMap,
/// Extract path
@@ -654,7 +670,9 @@ impl Update {
if let Some(timeout) = self.timeout {
request = request.timeout(timeout);
}
if let Some(ref proxy) = self.proxy {
if self.no_proxy {
request = request.no_proxy();
} else if let Some(ref proxy) = self.proxy {
let proxy = reqwest::Proxy::all(proxy.as_str())?;
request = request.proxy(proxy);
}