From fa43b4bf5d267f7e8cf0dc84ada2749ff3e1b6ca Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sun, 19 Nov 2023 12:49:08 +0100 Subject: [PATCH] Use proxy for fetching release metadata --- crates/typst-cli/src/download.rs | 10 ++++++++-- crates/typst-cli/src/update.rs | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/typst-cli/src/download.rs b/crates/typst-cli/src/download.rs index 9db73fe86..e5a97cda4 100644 --- a/crates/typst-cli/src/download.rs +++ b/crates/typst-cli/src/download.rs @@ -37,6 +37,13 @@ static TLS_CONFIG: Lazy>> = Lazy::new(|| { /// Download binary data and display its progress. #[allow(clippy::result_large_err)] pub fn download_with_progress(url: &str) -> Result, ureq::Error> { + let response = download(url)?; + Ok(RemoteReader::from_response(response).download()?) +} + +/// Download from a URL. +#[allow(clippy::result_large_err)] +pub fn download(url: &str) -> Result { let mut builder = ureq::AgentBuilder::new() .user_agent(concat!("typst/{}", env!("CARGO_PKG_VERSION"))); @@ -54,8 +61,7 @@ pub fn download_with_progress(url: &str) -> Result, ureq::Error> { } let agent = builder.build(); - let response = agent.get(url).call()?; - Ok(RemoteReader::from_response(response).download()?) + agent.get(url).call() } /// A wrapper around [`ureq::Response`] that reads the response body in chunks diff --git a/crates/typst-cli/src/update.rs b/crates/typst-cli/src/update.rs index 95418d038..f3a751632 100644 --- a/crates/typst-cli/src/update.rs +++ b/crates/typst-cli/src/update.rs @@ -11,7 +11,7 @@ use xz2::bufread::XzDecoder; use zip::ZipArchive; use crate::args::UpdateCommand; -use crate::download::download_with_progress; +use crate::download::{download, download_with_progress}; const TYPST_GITHUB_ORG: &str = "typst"; const TYPST_REPO: &str = "typst"; @@ -111,7 +111,7 @@ impl Release { ), }; - match ureq::get(&url).call() { + match download(&url) { Ok(response) => response .into_json() .map_err(|err| eco_format!("unable to parse JSON response: {err}")),