From a6ef17d6471d7a367ef5ee43f56ecd1b16d7bce1 Mon Sep 17 00:00:00 2001 From: goenning Date: Sun, 16 Feb 2025 15:12:29 +0000 Subject: [PATCH] add on_before_request --- plugins/updater/src/updater.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index f9209a00..d9531938 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -93,6 +93,7 @@ impl RemoteRelease { } pub type OnBeforeExit = Arc; +pub type OnBeforeRequest = Arc ClientBuilder + Send + Sync + 'static>; pub type VersionComparator = Arc bool + Send + Sync>; type MainThreadClosure = Box; type RunOnMainThread = @@ -114,6 +115,7 @@ pub struct UpdaterBuilder { installer_args: Vec, current_exe_args: Vec, on_before_exit: Option, + on_before_request: Option, } impl UpdaterBuilder { @@ -140,6 +142,7 @@ impl UpdaterBuilder { timeout: None, proxy: None, on_before_exit: None, + on_before_request: None, } } @@ -239,6 +242,11 @@ impl UpdaterBuilder { self } + pub fn on_before_request ClientBuilder + Send + Sync + 'static>(mut self, f: F) -> Self { + self.on_before_request.replace(Arc::new(f)); + self + } + pub fn build(self) -> Result { let endpoints = self .endpoints @@ -282,6 +290,7 @@ impl UpdaterBuilder { headers: self.headers, extract_path, on_before_exit: self.on_before_exit, + on_before_request: self.on_before_request, }) } } @@ -316,6 +325,7 @@ pub struct Updater { headers: HeaderMap, extract_path: PathBuf, on_before_exit: Option, + on_before_request: Option, #[allow(unused)] installer_args: Vec, #[allow(unused)] @@ -376,6 +386,11 @@ impl Updater { let proxy = reqwest::Proxy::all(proxy.as_str())?; request = request.proxy(proxy); } + + if let Some(ref on_before_request) = self.on_before_request { + request = on_before_request(request); + } + let response = request .build()? .get(url)