mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 08:22:59 +01:00
simplify pipeline
This commit is contained in:
parent
3c6c1268c9
commit
8cda362866
@ -251,23 +251,14 @@ 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) => {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
21
src/route.rs
21
src/route.rs
@ -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) => {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
37
src/scope.rs
37
src/scope.rs
@ -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) => {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user