diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 95eac76..a43a0d9 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -16,7 +16,7 @@ use super::request::{self, Request, RequestBuilder}; use super::response::{self, Response}; use connect::Connector; use into_url::to_uri; -use redirect::{self, RedirectPolicy, check_redirect, remove_sensitive_headers}; +use redirect::{self, RedirectPolicy, remove_sensitive_headers}; use {Certificate, Identity, IntoUrl, Method, Proxy, StatusCode, Url}; static DEFAULT_USER_AGENT: &'static str = @@ -475,8 +475,7 @@ impl Future for PendingRequest { } } self.urls.push(self.url.clone()); - let action = check_redirect( - &self.client.redirect_policy, + let action = self.client.redirect_policy.check( res.status(), &loc, &self.urls, diff --git a/src/redirect.rs b/src/redirect.rs index 0ba589c..d3352fa 100644 --- a/src/redirect.rs +++ b/src/redirect.rs @@ -128,6 +128,21 @@ impl RedirectPolicy { Policy::None => attempt.stop(), } } + + pub(crate) fn check( + &self, + status: StatusCode, + next: &Url, + previous: &[Url], + ) -> Action { + self + .redirect(RedirectAttempt { + status: status, + next: next, + previous: previous, + }) + .inner + } } impl Default for RedirectPolicy { @@ -205,30 +220,15 @@ impl fmt::Debug for Policy { // pub(crate) #[derive(Debug, PartialEq)] -pub enum Action { +pub(crate) enum Action { Follow, Stop, LoopDetected, TooManyRedirects, } -#[inline] -pub fn check_redirect( - policy: &RedirectPolicy, - status: StatusCode, - next: &Url, - previous: &[Url], -) -> Action { - policy - .redirect(RedirectAttempt { - status: status, - next: next, - previous: previous, - }) - .inner -} -pub fn remove_sensitive_headers(headers: &mut HeaderMap, next: &Url, previous: &[Url]) { +pub(crate) fn remove_sensitive_headers(headers: &mut HeaderMap, next: &Url, previous: &[Url]) { if let Some(previous) = previous.last() { let cross_host = next.host_str() != previous.host_str() || next.port_or_known_default() != previous.port_or_known_default(); @@ -268,14 +268,14 @@ fn test_redirect_policy_limit() { .collect::>(); assert_eq!( - check_redirect(&policy, StatusCode::FOUND, &next, &previous), + policy.check(StatusCode::FOUND, &next, &previous), Action::Follow ); previous.push(Url::parse("http://a.b.d/e/33").unwrap()); assert_eq!( - check_redirect(&policy, StatusCode::FOUND, &next, &previous), + policy.check(StatusCode::FOUND, &next, &previous), Action::TooManyRedirects ); } @@ -292,13 +292,13 @@ fn test_redirect_policy_custom() { let next = Url::parse("http://bar/baz").unwrap(); assert_eq!( - check_redirect(&policy, StatusCode::FOUND, &next, &[]), + policy.check(StatusCode::FOUND, &next, &[]), Action::Follow ); let next = Url::parse("http://foo/baz").unwrap(); assert_eq!( - check_redirect(&policy, StatusCode::FOUND, &next, &[]), + policy.check(StatusCode::FOUND, &next, &[]), Action::Stop ); }