Launcher downloads go through the proxy the player sets
Everything the launcher fetches now goes through one HTTP proxy when there is one: Horizon's releases and the launcher's own update, Minecraft's files and Java from Mojang, Modrinth, CurseForge, the mod registry, pictures, Microsoft sign-in, Tailscale's API, and the jars a modpack import downloads. It is Settings' Proxy row (`proxy` in settings.json), or `horizon-launcher settings proxy http://host:port`; without one, HTTPS_PROXY, HTTP_PROXY and ALL_PROXY apply, with NO_PROXY naming the hosts to reach directly. A local address never goes through it, and the Servers page's calls to a game server's API stay direct: they are on loopback and asked every second. horizon-port-pack builds its own agents, so the launcher hands it the address (net.rs); run on its own, it reads the same variables. Co-Authored-By: WorkBuddy AI (DeepSeek-V4.1-Flash) <noreply@workbuddy.cn>
This commit is contained in:
@@ -50,7 +50,7 @@ impl CurseForge {
|
||||
}
|
||||
|
||||
fn get(&self, url: &str) -> Result<Value, String> {
|
||||
let response = super::download::agent()
|
||||
let response = super::download::agent(url)
|
||||
.get(url)
|
||||
.set("x-api-key", &self.key)
|
||||
.set("Accept", "application/json")
|
||||
|
||||
@@ -17,16 +17,20 @@ const HOSTS: [&str; 4] = [
|
||||
/// Bigger than any pack these sources serve (Modrinth caps uploads at 500 MiB).
|
||||
const MAX: u64 = 1 << 30;
|
||||
|
||||
/// The HTTP agent the sources share. Modrinth asks for a user agent that names the project.
|
||||
pub(super) fn agent() -> ureq::Agent {
|
||||
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))
|
||||
.build()
|
||||
/// 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.
|
||||
pub(super) fn agent(url: &str) -> ureq::Agent {
|
||||
crate::proxy::agent(
|
||||
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()
|
||||
}
|
||||
|
||||
/// Why a file can't be downloaded at all, before any byte is read.
|
||||
@@ -159,9 +163,12 @@ pub fn fetch(file: &FileRef, folder: &Path, progress: &dyn Fn(f32)) -> Result<Pa
|
||||
if let Some(why) = refuse(file) {
|
||||
return Err(why);
|
||||
}
|
||||
let response = agent().get(&file.url).call().map_err(|e| match e {
|
||||
ureq::Error::Status(code, _) => format!("{} answered {code}.", file.url),
|
||||
ureq::Error::Transport(t) => format!("No connection: {t}"),
|
||||
})?;
|
||||
let response = agent(&file.url)
|
||||
.get(&file.url)
|
||||
.call()
|
||||
.map_err(|e| match e {
|
||||
ureq::Error::Status(code, _) => format!("{} answered {code}.", file.url),
|
||||
ureq::Error::Transport(t) => format!("No connection: {t}"),
|
||||
})?;
|
||||
save(file, response.into_reader(), folder, progress)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ fn fetch_index() -> Result<(Index, String), String> {
|
||||
use std::io::Read;
|
||||
let at = location();
|
||||
let text = if at.starts_with("https://") {
|
||||
let response = download::agent().get(&at).call().map_err(|e| match e {
|
||||
let response = download::agent(&at).get(&at).call().map_err(|e| match e {
|
||||
ureq::Error::Status(code, _) => format!("The mod registry answered {code}."),
|
||||
ureq::Error::Transport(t) => format!("The mod registry can't be reached: {t}"),
|
||||
})?;
|
||||
|
||||
@@ -63,7 +63,7 @@ pub fn fetch(home: &Path, url: &str, size: u32) -> Result<PathBuf, String> {
|
||||
if let Some(why) = refuse(url) {
|
||||
return Err(format!("{url}: {why}"));
|
||||
}
|
||||
let response = super::download::agent()
|
||||
let response = super::download::agent(url)
|
||||
.get(url)
|
||||
.call()
|
||||
.map_err(|e| format!("{url}: {e}"))?;
|
||||
|
||||
@@ -221,7 +221,7 @@ impl Source for Modrinth {
|
||||
}
|
||||
|
||||
fn get(url: &str) -> Result<Value, String> {
|
||||
let response = super::download::agent()
|
||||
let response = super::download::agent(url)
|
||||
.get(url)
|
||||
.call()
|
||||
.map_err(|e| match e {
|
||||
|
||||
Reference in New Issue
Block a user