1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-28 01:52:57 +01:00

simplify pipeline

This commit is contained in:
Nikolay Kim 2018-05-07 16:09:41 -07:00
parent 3c6c1268c9
commit 8cda362866
3 changed files with 33 additions and 50 deletions

View File

@ -251,8 +251,7 @@ impl<S: 'static, H: PipelineHandler<S>> StartMiddlewares<S, H> {
Ok(Started::Response(resp)) => { Ok(Started::Response(resp)) => {
return RunMiddlewares::init(info, resp) return RunMiddlewares::init(info, resp)
} }
Ok(Started::Future(mut fut)) => match fut.poll() { Ok(Started::Future(fut)) => {
Ok(Async::NotReady) => {
return PipelineState::Starting(StartMiddlewares { return PipelineState::Starting(StartMiddlewares {
hnd, hnd,
htype, htype,
@ -260,14 +259,6 @@ impl<S: 'static, H: PipelineHandler<S>> StartMiddlewares<S, H> {
_s: PhantomData, _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()),
},
Err(err) => return ProcessResponse::init(err.into()), Err(err) => return ProcessResponse::init(err.into()),
} }
} }

View File

@ -346,21 +346,12 @@ impl<S: 'static> StartMiddlewares<S> {
Ok(MiddlewareStarted::Response(resp)) => { Ok(MiddlewareStarted::Response(resp)) => {
return RunMiddlewares::init(info, resp) return RunMiddlewares::init(info, resp)
} }
Ok(MiddlewareStarted::Future(mut fut)) => match fut.poll() { Ok(MiddlewareStarted::Future(fut)) => {
Ok(Async::NotReady) => {
return ComposeState::Starting(StartMiddlewares { return ComposeState::Starting(StartMiddlewares {
fut: Some(fut), fut: Some(fut),
_s: PhantomData, _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()),
},
Err(err) => return FinishingMiddlewares::init(info, err.into()), Err(err) => return FinishingMiddlewares::init(info, err.into()),
} }
} }

View File

@ -521,21 +521,12 @@ impl<S: 'static> StartMiddlewares<S> {
Ok(MiddlewareStarted::Response(resp)) => { Ok(MiddlewareStarted::Response(resp)) => {
return RunMiddlewares::init(info, resp) return RunMiddlewares::init(info, resp)
} }
Ok(MiddlewareStarted::Future(mut fut)) => match fut.poll() { Ok(MiddlewareStarted::Future(fut)) => {
Ok(Async::NotReady) => {
return ComposeState::Starting(StartMiddlewares { return ComposeState::Starting(StartMiddlewares {
fut: Some(fut), fut: Some(fut),
_s: PhantomData, _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()),
},
Err(err) => return Response::init(err.into()), Err(err) => return Response::init(err.into()),
} }
} }
@ -795,7 +786,11 @@ mod tests {
fn test_scope_route() { fn test_scope_route() {
let mut app = App::new() let mut app = App::new()
.scope("app", |scope| { .scope("app", |scope| {
scope.route("/path1", Method::GET, |r: HttpRequest<_>| { scope
.route("/path1", Method::GET, |r: HttpRequest<_>| {
HttpResponse::Ok()
})
.route("/path1", Method::DELETE, |r: HttpRequest<_>| {
HttpResponse::Ok() HttpResponse::Ok()
}) })
}) })
@ -805,6 +800,12 @@ mod tests {
let resp = app.run(req); let resp = app.run(req);
assert_eq!(resp.as_msg().status(), StatusCode::OK); 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") let req = TestRequest::with_uri("/app/path1")
.method(Method::POST) .method(Method::POST)
.finish(); .finish();