aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/download.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/download.rs b/src/download.rs
index 537dae3..9e126dd 100644
--- a/src/download.rs
+++ b/src/download.rs
@@ -1,8 +1,11 @@
use std::path::{Path, PathBuf};
-use anyhow::Error;
+use anyhow::{Error, Context};
use fehler::throws;
-use hyper::{body::HttpBody, Client, header::CONTENT_TYPE, Uri};
+use hyper::Uri;
+use hyper::body::HttpBody;
+use hyper::client::Client;
+use hyper::header::{CONTENT_TYPE, LOCATION};
use tokio::fs;
use tokio::io::AsyncWriteExt;
@@ -22,6 +25,13 @@ pub(crate) async fn download(url: Uri, args: &Args) {
let client = Client::new();
let mut response = client.get(url.clone()).await?;
+ while response.status().is_redirection() {
+ let location = response.headers()
+ .get(LOCATION).context("no Location header in redirect")?
+ .to_str().context("malformed Location header in redirect")?
+ .parse().context("non-URL Location header in redirect")?;
+ response = client.get(location).await?;
+ }
if !response.status().is_success() {
panic!("non-success response code {} in URL {}", response.status(), url);
}