From 8cda36286673c887e6ae4b4eb17d18cef71d4a42 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 7 May 2018 16:09:41 -0700 Subject: [PATCH] simplify pipeline --- src/pipeline.rs | 25 ++++++++----------------- src/route.rs | 21 ++++++--------------- src/scope.rs | 37 +++++++++++++++++++------------------ 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/pipeline.rs b/src/pipeline.rs index 1b621882f..25fe11e1d 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -251,23 +251,14 @@ impl> StartMiddlewares { Ok(Started::Response(resp)) => { return RunMiddlewares::init(info, resp) } - Ok(Started::Future(mut fut)) => match fut.poll() { - Ok(Async::NotReady) => { - return PipelineState::Starting(StartMiddlewares { - hnd, - htype, - fut: Some(fut), - _s: PhantomData, - }) - } - Ok(Async::Ready(resp)) => { - if let Some(resp) = resp { - return RunMiddlewares::init(info, resp); - } - info.count += 1; - } - Err(err) => return ProcessResponse::init(err.into()), - }, + Ok(Started::Future(fut)) => { + return PipelineState::Starting(StartMiddlewares { + hnd, + htype, + fut: Some(fut), + _s: PhantomData, + }) + } Err(err) => return ProcessResponse::init(err.into()), } } diff --git a/src/route.rs b/src/route.rs index d17f13f11..215a7f226 100644 --- a/src/route.rs +++ b/src/route.rs @@ -346,21 +346,12 @@ impl StartMiddlewares { Ok(MiddlewareStarted::Response(resp)) => { return RunMiddlewares::init(info, resp) } - Ok(MiddlewareStarted::Future(mut fut)) => match fut.poll() { - Ok(Async::NotReady) => { - return ComposeState::Starting(StartMiddlewares { - fut: Some(fut), - _s: PhantomData, - }) - } - Ok(Async::Ready(resp)) => { - if let Some(resp) = resp { - return RunMiddlewares::init(info, resp); - } - info.count += 1; - } - Err(err) => return FinishingMiddlewares::init(info, err.into()), - }, + Ok(MiddlewareStarted::Future(fut)) => { + return ComposeState::Starting(StartMiddlewares { + fut: Some(fut), + _s: PhantomData, + }) + } Err(err) => return FinishingMiddlewares::init(info, err.into()), } } diff --git a/src/scope.rs b/src/scope.rs index e5d160bbe..c399ac76a 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -521,21 +521,12 @@ impl StartMiddlewares { Ok(MiddlewareStarted::Response(resp)) => { return RunMiddlewares::init(info, resp) } - Ok(MiddlewareStarted::Future(mut fut)) => match fut.poll() { - Ok(Async::NotReady) => { - return ComposeState::Starting(StartMiddlewares { - fut: Some(fut), - _s: PhantomData, - }) - } - Ok(Async::Ready(resp)) => { - if let Some(resp) = resp { - return RunMiddlewares::init(info, resp); - } - info.count += 1; - } - Err(err) => return Response::init(err.into()), - }, + Ok(MiddlewareStarted::Future(fut)) => { + return ComposeState::Starting(StartMiddlewares { + fut: Some(fut), + _s: PhantomData, + }) + } Err(err) => return Response::init(err.into()), } } @@ -795,9 +786,13 @@ mod tests { fn test_scope_route() { let mut app = App::new() .scope("app", |scope| { - scope.route("/path1", Method::GET, |r: HttpRequest<_>| { - HttpResponse::Ok() - }) + scope + .route("/path1", Method::GET, |r: HttpRequest<_>| { + HttpResponse::Ok() + }) + .route("/path1", Method::DELETE, |r: HttpRequest<_>| { + HttpResponse::Ok() + }) }) .finish(); @@ -805,6 +800,12 @@ mod tests { let resp = app.run(req); assert_eq!(resp.as_msg().status(), StatusCode::OK); + let req = TestRequest::with_uri("/app/path1") + .method(Method::DELETE) + .finish(); + let resp = app.run(req); + assert_eq!(resp.as_msg().status(), StatusCode::OK); + let req = TestRequest::with_uri("/app/path1") .method(Method::POST) .finish();