diff --git a/actix-http/src/message.rs b/actix-http/src/message.rs index 8c401a5ba..1a5500c31 100644 --- a/actix-http/src/message.rs +++ b/actix-http/src/message.rs @@ -387,6 +387,12 @@ impl BoxedResponseHead { pub fn new(status: StatusCode) -> Self { RESPONSE_POOL.with(|p| p.get_message(status)) } + + pub(crate) fn take(&mut self) -> Self { + BoxedResponseHead { + head: self.head.take(), + } + } } impl std::ops::Deref for BoxedResponseHead { diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs index 19feb5633..df2f5be50 100644 --- a/actix-http/src/response.rs +++ b/actix-http/src/response.rs @@ -1,6 +1,9 @@ //! Http response use std::cell::{Ref, RefMut}; use std::convert::TryFrom; +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; use std::{fmt, str}; use bytes::{Bytes, BytesMut}; @@ -278,6 +281,18 @@ impl fmt::Debug for Response { } } +impl Future for Response { + type Output = Result; + + fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Ready(Ok(Response { + head: self.head.take(), + body: self.body.take_body(), + error: self.error.take(), + })) + } +} + pub struct CookieIter<'a> { iter: header::GetAll<'a>, } @@ -741,6 +756,14 @@ impl<'a> From<&'a ResponseHead> for ResponseBuilder { } } +impl Future for ResponseBuilder { + type Output = Result; + + fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll { + Poll::Ready(Ok(self.finish())) + } +} + impl fmt::Debug for ResponseBuilder { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let head = self.head.as_ref().unwrap();