From 82f577c17d236b1ec32cc1a511c910c1c90afbab Mon Sep 17 00:00:00 2001 From: James Wykeham-Martin Date: Fri, 2 Feb 2018 09:38:06 +0000 Subject: [PATCH] Added custom redirect policy --- hammond-downloader/src/downloader.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index dd813b8..5ecdc64 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -2,6 +2,7 @@ use glob::glob; use hyper::header::*; use mime_guess; use reqwest; +use reqwest::RedirectPolicy; use tempdir::TempDir; use std::fs; @@ -37,7 +38,18 @@ fn download_into( progress: Option>>, ) -> Result { info!("GET request to: {}", url); - let client = reqwest::Client::builder().referer(false).build()?; + // Haven't included the loop check as + // Steal the Stars + let policy = RedirectPolicy::custom(|attempt| { + info!("Redirect Attempt URL: {:?}", attempt.url()); + if attempt.previous().len() > 10 { + attempt.too_many_redirects() + } else { + attempt.follow() + } + }); + + let client = reqwest::Client::builder().redirect(policy).referer(false).build()?; let mut resp = client.get(url).send()?; info!("Status Resp: {}", resp.status());