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:
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user