From e87e636e840ca768a5d583af91d2dd80e5fb0154 Mon Sep 17 00:00:00 2001 From: joshbenaron <73971531+joshbenaron@users.noreply.github.com> Date: Fri, 2 Apr 2021 19:06:39 +0100 Subject: [PATCH] Fix formatting --- awc/src/middleware/retry.rs | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/awc/src/middleware/retry.rs b/awc/src/middleware/retry.rs index 6e5957339..1f052f223 100644 --- a/awc/src/middleware/retry.rs +++ b/awc/src/middleware/retry.rs @@ -60,8 +60,8 @@ impl Retry { /// .finish(); ///``` pub fn policy(mut self, p: T) -> Self - where - T: IntoRetryPolicy, + where + T: IntoRetryPolicy, { self.0.policies.push(p.into_policy()); self @@ -79,8 +79,8 @@ pub trait IntoRetryPolicy { } impl IntoRetryPolicy for T - where - T: for<'a> Fn(StatusCode, &'a HeaderMap) -> bool + 'static, +where + T: for<'a> Fn(StatusCode, &'a HeaderMap) -> bool + 'static, { fn into_policy(self) -> RetryPolicy { RetryPolicy::Custom(Box::new(self)) @@ -94,8 +94,8 @@ impl IntoRetryPolicy for Vec { } impl Transform for Retry - where - S: Service + 'static, +where + S: Service + 'static, { type Transform = RetryService; @@ -116,8 +116,8 @@ pub struct RetryService { } impl Service for RetryService - where - S: Service + 'static, +where + S: Service + 'static, { type Response = S::Response; type Error = S::Error; @@ -135,7 +135,7 @@ impl Service for RetryService Box::pin(async move { match req { ConnectRequest::Client(head, body, addr) => { - for _ in 1..max_retry { + for _ in 0..max_retry { let h = clone_request_head_type(&head); let result = connector @@ -168,11 +168,8 @@ impl Service for RetryService // Exceed max retry so just return whatever response is received log::debug!("Request max retry reached"); - connector.call(ConnectRequest::Client( - head, - body, - addr, - )) + connector + .call(ConnectRequest::Client(head, body, addr)) .await } ConnectRequest::Tunnel(head, addr) => { @@ -189,13 +186,14 @@ impl Service for RetryService } } ConnectResponse::Tunnel(head, _) => { - if is_valid_response(&policies, head.status, head.headers()) { + if is_valid_response(&policies, head.status, head.headers()) + { return Ok(res); } } } } - }; + } // Exceed max retry so just return whatever response is received log::debug!("Request max retry reached"); @@ -210,7 +208,7 @@ fn body_to_retry_body(body: &Body) -> Body { match body { Body::Empty => Body::Empty, Body::Bytes(b) => Body::Bytes(b.clone()), - _ => Body::None + _ => Body::None, } } @@ -280,12 +278,9 @@ mod tests { #[actix_rt::test] async fn test_basic_policy() { - std::env::set_var("RUST_LOG", "RUST_LOG=debug,a=debug"); - env_logger::init(); - let client = ClientBuilder::new() .disable_redirects() - .wrap(Retry::new(3).policy(vec![StatusCode::INTERNAL_SERVER_ERROR])) + .wrap(Retry::new(1).policy(vec![StatusCode::INTERNAL_SERVER_ERROR])) .finish(); let srv = actix_test::start(|| { @@ -304,7 +299,7 @@ mod tests { let client = ClientBuilder::new() .disable_redirects() .wrap( - Retry::new(3).policy(|code: StatusCode, headers: &HeaderMap| { + Retry::new(2).policy(|code: StatusCode, headers: &HeaderMap| { code.is_success() && headers.contains_key("SOME_HEADER") }), )