diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-11-19 12:49:08 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-11-19 12:49:08 +0100 |
| commit | fa43b4bf5d267f7e8cf0dc84ada2749ff3e1b6ca (patch) | |
| tree | 0ca740ada3db3f56449485904869f64a1eca9eca | |
| parent | e0d6526a53db562fb26d3fcfba091412d3c93bf4 (diff) | |
Use proxy for fetching release metadata
| -rw-r--r-- | crates/typst-cli/src/download.rs | 10 | ||||
| -rw-r--r-- | 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 9db73fe8..e5a97cda 100644 --- a/crates/typst-cli/src/download.rs +++ b/crates/typst-cli/src/download.rs @@ -37,6 +37,13 @@ static TLS_CONFIG: Lazy<Option<Arc<rustls::ClientConfig>>> = Lazy::new(|| { /// Download binary data and display its progress. #[allow(clippy::result_large_err)] pub fn download_with_progress(url: &str) -> Result<Vec<u8>, 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<ureq::Response, ureq::Error> { 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<Vec<u8>, 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 95418d03..f3a75163 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}")), |
