mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
commit
e8582c14cc
@ -70,7 +70,7 @@ fn step_x_v1(data: SomeData) -> Box<Future<Item = SomeData, Error = Error>> {
|
|||||||
.map_err(Error::from) // <- convert SendRequestError to an Error
|
.map_err(Error::from) // <- convert SendRequestError to an Error
|
||||||
.and_then(
|
.and_then(
|
||||||
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
||||||
.from_err() // <- convert PayloadError to a Error
|
.from_err() // <- convert PayloadError to an Error
|
||||||
.and_then(|body| {
|
.and_then(|body| {
|
||||||
let resp: HttpBinResponse = serde_json::from_slice(&body).unwrap();
|
let resp: HttpBinResponse = serde_json::from_slice(&body).unwrap();
|
||||||
fut_ok(resp.json)
|
fut_ok(resp.json)
|
||||||
@ -109,7 +109,7 @@ fn step_x_v2(data: SomeData) -> impl Future<Item = SomeData, Error = Error> {
|
|||||||
.map_err(Error::from) // <- convert SendRequestError to an Error
|
.map_err(Error::from) // <- convert SendRequestError to an Error
|
||||||
.and_then(
|
.and_then(
|
||||||
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
||||||
.from_err() // <- convert PayloadError to a Error
|
.from_err() // <- convert PayloadError to an Error
|
||||||
.and_then(|body| {
|
.and_then(|body| {
|
||||||
let resp: HttpBinResponse = serde_json::from_slice(&body).unwrap();
|
let resp: HttpBinResponse = serde_json::from_slice(&body).unwrap();
|
||||||
fut_ok(resp.json)
|
fut_ok(resp.json)
|
||||||
|
@ -17,7 +17,7 @@ fn index(_req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
|
|||||||
.map_err(Error::from) // <- convert SendRequestError to an Error
|
.map_err(Error::from) // <- convert SendRequestError to an Error
|
||||||
.and_then(
|
.and_then(
|
||||||
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
|resp| resp.body() // <- this is MessageBody type, resolves to complete body
|
||||||
.from_err() // <- convert PayloadError to a Error
|
.from_err() // <- convert PayloadError to an Error
|
||||||
.and_then(|body| { // <- we got complete body, now send as server response
|
.and_then(|body| { // <- we got complete body, now send as server response
|
||||||
Ok(HttpResponse::Ok().body(body))
|
Ok(HttpResponse::Ok().body(body))
|
||||||
}))
|
}))
|
||||||
@ -34,7 +34,7 @@ fn streaming(_req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error
|
|||||||
.and_then(|resp| { // <- we received client response
|
.and_then(|resp| { // <- we received client response
|
||||||
Ok(HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
// read one chunk from client response and send this chunk to a server response
|
// read one chunk from client response and send this chunk to a server response
|
||||||
// .from_err() converts PayloadError to a Error
|
// .from_err() converts PayloadError to an Error
|
||||||
.body(Body::Streaming(Box::new(resp.from_err()))))
|
.body(Body::Streaming(Box::new(resp.from_err()))))
|
||||||
})
|
})
|
||||||
.responder()
|
.responder()
|
||||||
|
Loading…
Reference in New Issue
Block a user