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

View File

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

View File

@ -521,21 +521,12 @@ impl<S: 'static> StartMiddlewares<S> {
Ok(MiddlewareStarted::Response(resp)) => {
return RunMiddlewares::init(info, resp)
}
Ok(MiddlewareStarted::Future(mut fut)) => match fut.poll() {
Ok(Async::NotReady) => {
Ok(MiddlewareStarted::Future(fut)) => {
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()),
},
Err(err) => return Response::init(err.into()),
}
}
@ -795,7 +786,11 @@ mod tests {
fn test_scope_route() {
let mut app = App::new()
.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()
})
})
@ -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();