From cd7dbe226c61e891de7682e7d5da2206251fe7c4 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Fri, 21 Sep 2018 14:22:41 -0700 Subject: [PATCH] log invalid location header value on error --- src/async_impl/client.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index f3a9576..db6a844 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -476,9 +476,17 @@ impl Future for PendingRequest { if should_redirect { let loc = res.headers() .get(LOCATION) - .and_then(|val| val.to_str().ok()) - .map(|loc| self.url.join(loc)); - if let Some(Ok(loc)) = loc { + .and_then(|val| { + let loc = (|| -> Option { + self.url.join(val.to_str().ok()?).ok() + })(); + + if loc.is_none() { + debug!("Location header had invalid URI: {:?}", val); + } + loc + }); + if let Some(loc) = loc { if self.client.referer { if let Some(referer) = make_referer(&loc, &self.url) { self.headers.insert(REFERER, referer); @@ -522,8 +530,6 @@ impl Future for PendingRequest { return Err(::error::too_many_redirects(self.url.clone())); } } - } else if let Some(Err(e)) = loc { - debug!("Location header had invalid URI: {:?}", e); } } let res = Response::new(res, self.url.clone(), self.client.gzip);