1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 18:09:22 +02:00

refactor http actor usage

This commit is contained in:
Nikolay Kim
2017-12-31 17:26:32 -08:00
parent 967d3244d7
commit cc38b30f7b
22 changed files with 197 additions and 254 deletions

View File

@ -72,7 +72,7 @@ Create `Logger` middleware with the specified `format`.
Default `Logger` could be created with `default` method, it uses the default format:
```ignore
%a %t "%r" %s %b "%{Referrer}i" "%{User-Agent}i" %T
%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i" %T
```
```rust
# extern crate actix_web;

View File

@ -110,7 +110,7 @@ fn index(req: HttpRequest<State>) -> Box<Future<Item=HttpResponse, Error=Error>>
.and_then(|res| {
match res {
Ok(user) => Ok(httpcodes::HTTPOk.build().json(user)?),
Err(_) => Ok(httpcodes::HTTPInternalServerError.response())
Err(_) => Ok(httpcodes::HTTPInternalServerError.into())
}
})
.responder()

View File

@ -65,7 +65,7 @@ impl<S> Handler<S> for MyHandler {
/// Handle request
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
self.0 += 1;
httpcodes::HTTPOk.response()
httpcodes::HTTPOk.into()
}
}
# fn main() {}
@ -91,7 +91,7 @@ impl<S> Handler<S> for MyHandler {
fn handle(&mut self, req: HttpRequest<S>) -> Self::Result {
let num = self.0.load(Ordering::Relaxed) + 1;
self.0.store(num, Ordering::Relaxed);
httpcodes::HTTPOk.response()
httpcodes::HTTPOk.into()
}
}
@ -104,7 +104,7 @@ fn main() {
move || {
let cloned = inc.clone();
Application::new()
.resource("/", move |r| r.h(MyHandler(cloned)))
.resource("/", move |r| r.h(MyHandler(cloned)))
})
.bind("127.0.0.1:8088").unwrap()
.start();

View File

@ -246,7 +246,7 @@ fn index(mut req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
.from_err()
.and_then(|params| { // <- url encoded parameters
println!("==== BODY ==== {:?}", params);
ok(httpcodes::HTTPOk.response())
ok(httpcodes::HTTPOk.into())
})
.responder()
}

View File

@ -20,10 +20,10 @@ use actix_web::test::TestRequest;
fn index(req: HttpRequest) -> HttpResponse {
if let Some(hdr) = req.headers().get(header::CONTENT_TYPE) {
if let Ok(s) = hdr.to_str() {
return httpcodes::HTTPOk.response()
return httpcodes::HTTPOk.into()
}
}
httpcodes::HTTPBadRequest.response()
httpcodes::HTTPBadRequest.into()
}
fn main() {
@ -60,7 +60,7 @@ use actix_web::*;
use actix_web::test::TestServer;
fn index(req: HttpRequest) -> HttpResponse {
httpcodes::HTTPOk.response()
httpcodes::HTTPOk.into()
}
fn main() {
@ -80,7 +80,7 @@ use actix_web::*;
use actix_web::test::TestServer;
fn index(req: HttpRequest) -> HttpResponse {
httpcodes::HTTPOk.response()
httpcodes::HTTPOk.into()
}
/// This function get called by http server.