Use proxy for fetching release metadata

This commit is contained in:
Laurenz 2023-11-19 12:49:08 +01:00
parent e0d6526a53
commit fa43b4bf5d
2 changed files with 10 additions and 4 deletions

View File

@ -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

View File

@ -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}")),