Skip to content

Commit 24bebca

Browse files
authored
Merge pull request Stack-Cairn#188 from Stack-Cairn/fix/app-proxy-updater-coverage
fix(updater): route update check/download/install through the app proxy
2 parents 1748d6f + 754d31d commit 24bebca

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

crates/agent-gui/src-tauri/src/commands/app/update.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ fn build_updater(
452452
builder = builder.pubkey(public_key);
453453
}
454454

455+
// 更新下载/安装与 github_client() 的探测请求保持同一份应用代理配置;未启用时
456+
// 显式 no_proxy(),避免插件内部 client 兜底读取 OS 代理环境变量。
457+
builder = match crate::services::system_proxy::current_proxy_url()? {
458+
Some(proxy_url) => builder.proxy(proxy_url),
459+
None => builder.no_proxy(),
460+
};
461+
455462
builder
456463
.endpoints(vec![manifest_url])
457464
.map_err(|error| format!("invalid updater endpoint: {error}"))?

crates/agent-gui/src-tauri/src/services/system_proxy.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,21 @@ pub fn blocking_client_builder() -> Result<reqwest::blocking::ClientBuilder, Str
282282
blocking_client_builder_for_mode(&current_snapshot().mode)
283283
}
284284

285+
/// Resolved proxy URL for consumers that configure their own HTTP client rather
286+
/// than using `client_builder()`/`cached_client()` (e.g. `tauri-plugin-updater`,
287+
/// which only accepts a `Url` on its builder). `Ok(None)` means the app proxy is
288+
/// disabled — callers must still explicitly disable their own client's proxy in
289+
/// that case instead of leaving it to fall back to OS proxy env vars.
290+
pub fn current_proxy_url() -> Result<Option<reqwest::Url>, String> {
291+
match current_snapshot().mode {
292+
ProxyMode::Disabled => Ok(None),
293+
ProxyMode::Invalid(error) => Err(error),
294+
ProxyMode::Enabled(config) => reqwest::Url::parse(&config.proxy_url())
295+
.map(Some)
296+
.map_err(|_| format!("应用代理地址无效:{}", config.display_target())),
297+
}
298+
}
299+
285300
#[cfg(test)]
286301
mod tests {
287302
use super::*;
@@ -403,4 +418,28 @@ mod tests {
403418
.expect("disabled proxy envs")
404419
.is_empty());
405420
}
421+
422+
#[test]
423+
fn current_proxy_url_reflects_mode() {
424+
set_config(None);
425+
assert_eq!(current_proxy_url().expect("disabled proxy url"), None);
426+
427+
set_config(Some(&json!({
428+
"enabled": true, "type": "http", "host": "proxy.local", "port": 8080
429+
})));
430+
assert_eq!(
431+
current_proxy_url()
432+
.expect("enabled proxy url")
433+
.map(|url| url.to_string()),
434+
Some("http://proxy.local:8080/".to_string())
435+
);
436+
437+
set_config(Some(&json!({
438+
"enabled": true, "type": "http", "host": "bad host/@", "port": 8080
439+
})));
440+
assert!(current_proxy_url().is_err());
441+
442+
// reset so other tests in this module observe the default disabled state
443+
set_config(None);
444+
}
406445
}

0 commit comments

Comments
 (0)