mirror of
https://github.com/actix/actix-web.git
synced 2024-11-27 12:01:15 +00:00
more general Responder implementaiton for response future
This commit is contained in:
parent
821c96c37c
commit
c36ad06332
1 changed files with 15 additions and 3 deletions
|
@ -168,14 +168,26 @@ impl<A: Actor<Context=HttpContext<A, S>>, S: 'static> From<HttpContext<A, S>> fo
|
|||
}
|
||||
}
|
||||
|
||||
impl Responder for Box<Future<Item=HttpResponse, Error=Error>>
|
||||
impl<I, E> Responder for Box<Future<Item=I, Error=E>>
|
||||
where I: Responder + 'static,
|
||||
E: Into<Error> + 'static
|
||||
{
|
||||
type Item = Reply;
|
||||
type Error = Error;
|
||||
|
||||
#[inline]
|
||||
fn respond_to(self, _: HttpRequest) -> Result<Reply, Error> {
|
||||
Ok(Reply(ReplyItem::Future(self)))
|
||||
fn respond_to(self, req: HttpRequest) -> Result<Reply, Error> {
|
||||
let fut = self.map_err(|e| e.into())
|
||||
.then(move |r| {
|
||||
match r.respond_to(req) {
|
||||
Ok(reply) => match reply.into().0 {
|
||||
ReplyItem::Message(resp) => ok(resp),
|
||||
_ => panic!("Nested async replies are not supported"),
|
||||
},
|
||||
Err(e) => err(e),
|
||||
}
|
||||
});
|
||||
Ok(Reply::async(fut))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue