From af4b09432871f983ae65884c699ffd0238542178 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 16 Jul 2025 10:08:55 +0200 Subject: [PATCH 1/2] set a user-agent when downloading files --- src/downloader.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/downloader.rs b/src/downloader.rs index bf6e29b..1045f68 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -21,7 +21,9 @@ impl Downloader { pub(crate) fn new() -> Result { Ok(Self { storage: TempDir::new()?, - http: Client::new(), + http: Client::builder() + .user_agent("https://github.com/rust-lang/ci-mirrors") + .build()?, }) } From e5153b02ea8da5abe2de3b8d2c1e4b0dcf789c6f Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Wed, 16 Jul 2025 10:08:55 +0200 Subject: [PATCH 2/2] add better diagnostics when downloads fail --- src/downloader.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/downloader.rs b/src/downloader.rs index 1045f68..736b3d1 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -34,15 +34,16 @@ impl Downloader { }; eprintln!("downloading {url}..."); - let mut reader = StreamReader::new( - self.http - .get(url.clone()) - .send() - .await? - .error_for_status()? - .bytes_stream() - .map_err(std::io::Error::other), - ); + let resp = self.http.get(url.clone()).send().await?; + if !resp.status().is_success() { + bail!( + "failed to download with status {}: {url}\n=== body ===\n{}\n============\n", + resp.status(), + resp.text().await? + ); + } + + let mut reader = StreamReader::new(resp.bytes_stream().map_err(std::io::Error::other)); let dest = File::create(self.path_for(file)).await?; let mut writer = Sha256Writer::new(BufWriter::new(dest));