re purpose pr

This commit is contained in:
fakeshadow 2021-01-08 05:08:02 +08:00
parent 05ba1c5681
commit 2de3b542bd
2 changed files with 29 additions and 0 deletions

View File

@ -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 {

View File

@ -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<B: MessageBody> fmt::Debug for Response<B> {
}
}
impl Future for Response {
type Output = Result<Response, Error>;
fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
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<Response, Error>;
fn poll(mut self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
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();