diff --git a/.changes/add-updater-no-proxy.md b/.changes/add-updater-no-proxy.md new file mode 100644 index 0000000000..42641e063b --- /dev/null +++ b/.changes/add-updater-no-proxy.md @@ -0,0 +1,6 @@ +--- +"updater": minor +"updater-js": minor +--- + +Add no_proxy config to disable system proxy for updater plugin. diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 28c420ca86..a93c8a9c2d 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -146,6 +146,7 @@ pub struct UpdaterBuilder { headers: HeaderMap, timeout: Option, proxy: Option, + no_proxy: bool, installer_args: Vec, current_exe_args: Vec, on_before_exit: Option, @@ -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,11 @@ impl UpdaterBuilder { self } + pub fn no_proxy(mut self) -> Self { + self.no_proxy = true; + self + } + pub fn pubkey>(mut self, pubkey: S) -> Self { self.config.pubkey = pubkey.into(); self @@ -315,6 +322,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, @@ -349,6 +357,7 @@ pub struct Updater { version_comparator: Option, timeout: Option, proxy: Option, + no_proxy: bool, endpoints: Vec, arch: &'static str, // The `{{target}}` variable we replace in the endpoint and serach for in the JSON, @@ -428,7 +437,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); @@ -519,6 +531,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(), @@ -592,6 +605,8 @@ pub struct Update { pub timeout: Option, /// Request proxy pub proxy: Option, + /// Disable system proxy + pub no_proxy: bool, /// Request headers pub headers: HeaderMap, /// Extract path @@ -628,7 +643,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); }