Proxy: one copy of the rules, none of it per request

Co-Authored-By: WorkBuddy AI (DeepSeek-V4.1-Flash) <noreply@workbuddy.cn>
This commit is contained in:
zhykowo
2026-10-26 21:17:14 +08:00
parent a9453b7c93
commit da54f988d4
6 changed files with 312 additions and 217 deletions
+12 -6
View File
@@ -19,18 +19,24 @@ const MAX: u64 = 1 << 30;
/// The HTTP agent the sources share, reaching `url` through the player's proxy when one is set
/// (`proxy`). Modrinth asks for a user agent that names the project.
///
/// It is kept between downloads: a fresh agent starts a new connection pool, so one per file would
/// be a handshake per file, and a modpack brings hundreds.
pub(super) fn agent(url: &str) -> ureq::Agent {
crate::proxy::agent(
ureq::AgentBuilder::new()
let spec = crate::proxy::spec_for(url);
horizon_port_pack::net::keep("browser", spec.as_deref(), |proxy| {
let builder = ureq::AgentBuilder::new()
.user_agent(&format!(
"ludovic111/horizon horizon-launcher/{} (github.com/ludovic111/horizon)",
crate::backend::VERSION
))
.timeout_connect(std::time::Duration::from_secs(15))
.timeout_read(std::time::Duration::from_secs(60)),
url,
)
.build()
.timeout_read(std::time::Duration::from_secs(60));
match proxy {
Some(proxy) => builder.proxy(proxy).build(),
None => builder.build(),
}
})
}
/// Why a file can't be downloaded at all, before any byte is read.