1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-10 10:59:33 +00: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,23 +251,14 @@ 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, 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 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,9 +786,13 @@ 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
HttpResponse::Ok() .route("/path1", Method::GET, |r: HttpRequest<_>| {
}) HttpResponse::Ok()
})
.route("/path1", Method::DELETE, |r: HttpRequest<_>| {
HttpResponse::Ok()
})
}) })
.finish(); .finish();
@ -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();