mirror of
https://github.com/actix/actix-web.git
synced 2024-12-01 22:11:20 +00:00
better handler result handling
This commit is contained in:
parent
0bd8725426
commit
b55d69b4c2
4 changed files with 9 additions and 15 deletions
|
@ -78,10 +78,10 @@ fn main() {
|
||||||
.resource("/", |r| r.handler(Method::GET, |req| {
|
.resource("/", |r| r.handler(Method::GET, |req| {
|
||||||
println!("{:?}", req);
|
println!("{:?}", req);
|
||||||
|
|
||||||
Ok(httpcodes::HTTPFound
|
httpcodes::HTTPFound
|
||||||
.build()
|
.build()
|
||||||
.header("LOCATION", "/index.html")
|
.header("LOCATION", "/index.html")
|
||||||
.body(Body::Empty)?)
|
.body(Body::Empty)
|
||||||
}))
|
}))
|
||||||
// static files
|
// static files
|
||||||
.route_handler("/static", StaticFiles::new("examples/static/", true)))
|
.route_handler("/static", StaticFiles::new("examples/static/", true)))
|
||||||
|
|
|
@ -148,9 +148,7 @@ impl<S> ApplicationBuilder<S> where S: 'static {
|
||||||
/// let app = Application::default("/")
|
/// let app = Application::default("/")
|
||||||
/// .resource("/test", |r| {
|
/// .resource("/test", |r| {
|
||||||
/// r.get::<MyRoute>();
|
/// r.get::<MyRoute>();
|
||||||
/// r.handler(Method::HEAD, |req| {
|
/// r.handler(Method::HEAD, |req| httpcodes::HTTPMethodNotAllowed);
|
||||||
/// Ok(httpcodes::HTTPMethodNotAllowed)
|
|
||||||
/// });
|
|
||||||
/// })
|
/// })
|
||||||
/// .finish();
|
/// .finish();
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -205,11 +205,11 @@ impl HttpResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper conversion implementation
|
/// Helper conversion implementation
|
||||||
impl<I: Into<HttpResponse>, E: Into<HttpResponse>> From<Result<I, E>> for HttpResponse {
|
impl<I: Into<HttpResponse>, E: Into<Error>> From<Result<I, E>> for HttpResponse {
|
||||||
fn from(res: Result<I, E>) -> Self {
|
fn from(res: Result<I, E>) -> Self {
|
||||||
match res {
|
match res {
|
||||||
Ok(val) => val.into(),
|
Ok(val) => val.into(),
|
||||||
Err(err) => err.into(),
|
Err(err) => err.into().into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@ fn create_server<T, A>() -> HttpServer<T, A, Application<()>> {
|
||||||
HttpServer::new(
|
HttpServer::new(
|
||||||
vec![Application::default("/")
|
vec![Application::default("/")
|
||||||
.resource("/", |r|
|
.resource("/", |r|
|
||||||
r.handler(Method::GET, |_| {
|
r.handler(Method::GET, |_| httpcodes::HTTPOk))
|
||||||
Ok(httpcodes::HTTPOk)
|
|
||||||
}))
|
|
||||||
.finish()])
|
.finish()])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,9 +94,7 @@ fn test_middlewares() {
|
||||||
response: act_num2,
|
response: act_num2,
|
||||||
finish: act_num3})
|
finish: act_num3})
|
||||||
.resource("/", |r|
|
.resource("/", |r|
|
||||||
r.handler(Method::GET, |_| {
|
r.handler(Method::GET, |_| httpcodes::HTTPOk))
|
||||||
Ok(httpcodes::HTTPOk)
|
|
||||||
}))
|
|
||||||
.finish()])
|
.finish()])
|
||||||
.serve::<_, ()>("127.0.0.1:58904").unwrap();
|
.serve::<_, ()>("127.0.0.1:58904").unwrap();
|
||||||
sys.run();
|
sys.run();
|
||||||
|
|
Loading…
Reference in a new issue