1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 18:37:41 +02:00

update examples

This commit is contained in:
Nikolay Kim
2018-03-30 23:37:15 -07:00
parent 44e3df82f6
commit 7a743fa6b5
11 changed files with 28 additions and 33 deletions

View File

@ -18,9 +18,7 @@ fn index(_req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
.from_err() // <- convert PayloadError to a Error
.and_then(|body| { // <- we got complete body, now send as server response
HttpResponse::Ok()
.body(body)
.map_err(Error::from)
Ok(HttpResponse::Ok().body(body))
}))
.responder()
}
@ -33,11 +31,10 @@ fn streaming(_req: HttpRequest) -> Box<Future<Item=HttpResponse, Error=Error>> {
.send() // <- connect to host and send request
.map_err(Error::from) // <- convert SendRequestError to an Error
.and_then(|resp| { // <- we received client response
HttpResponse::Ok()
// read one chunk from client response and send this chunk to a server response
// .from_err() converts PayloadError to a Error
.body(Body::Streaming(Box::new(resp.from_err())))
.map_err(|e| e.into()) // HttpOk::build() maybe return HttpError, we need to convert it to a Error
Ok(HttpResponse::Ok()
// read one chunk from client response and send this chunk to a server response
// .from_err() converts PayloadError to a Error
.body(Body::Streaming(Box::new(resp.from_err()))))
})
.responder()
}