mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
use body::None in encoder body
This commit is contained in:
parent
5842a3279d
commit
ae47d96fc6
@ -25,7 +25,7 @@ use zstd::stream::write::Encoder as ZstdEncoder;
|
|||||||
|
|
||||||
use super::Writer;
|
use super::Writer;
|
||||||
use crate::{
|
use crate::{
|
||||||
body::{BodySize, MessageBody},
|
body::{self, BodySize, MessageBody},
|
||||||
error::BlockingError,
|
error::BlockingError,
|
||||||
header::{self, ContentEncoding, HeaderValue, CONTENT_ENCODING},
|
header::{self, ContentEncoding, HeaderValue, CONTENT_ENCODING},
|
||||||
ResponseHead, StatusCode,
|
ResponseHead, StatusCode,
|
||||||
@ -46,7 +46,9 @@ pin_project! {
|
|||||||
impl<B: MessageBody> Encoder<B> {
|
impl<B: MessageBody> Encoder<B> {
|
||||||
fn none() -> Self {
|
fn none() -> Self {
|
||||||
Encoder {
|
Encoder {
|
||||||
body: EncoderBody::None,
|
body: EncoderBody::None {
|
||||||
|
body: body::None::new(),
|
||||||
|
},
|
||||||
encoder: None,
|
encoder: None,
|
||||||
fut: None,
|
fut: None,
|
||||||
eof: true,
|
eof: true,
|
||||||
@ -96,7 +98,7 @@ impl<B: MessageBody> Encoder<B> {
|
|||||||
pin_project! {
|
pin_project! {
|
||||||
#[project = EncoderBodyProj]
|
#[project = EncoderBodyProj]
|
||||||
enum EncoderBody<B> {
|
enum EncoderBody<B> {
|
||||||
None,
|
None { body: body::None },
|
||||||
Full { body: Bytes },
|
Full { body: Bytes },
|
||||||
Stream { #[pin] body: B },
|
Stream { #[pin] body: B },
|
||||||
}
|
}
|
||||||
@ -111,7 +113,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn size(&self) -> BodySize {
|
fn size(&self) -> BodySize {
|
||||||
match self {
|
match self {
|
||||||
EncoderBody::None => BodySize::None,
|
EncoderBody::None { body } => body.size(),
|
||||||
EncoderBody::Full { body } => body.size(),
|
EncoderBody::Full { body } => body.size(),
|
||||||
EncoderBody::Stream { body } => body.size(),
|
EncoderBody::Stream { body } => body.size(),
|
||||||
}
|
}
|
||||||
@ -122,7 +124,9 @@ where
|
|||||||
cx: &mut Context<'_>,
|
cx: &mut Context<'_>,
|
||||||
) -> Poll<Option<Result<Bytes, Self::Error>>> {
|
) -> Poll<Option<Result<Bytes, Self::Error>>> {
|
||||||
match self.project() {
|
match self.project() {
|
||||||
EncoderBodyProj::None => Poll::Ready(None),
|
EncoderBodyProj::None { body } => {
|
||||||
|
Pin::new(body).poll_next(cx).map_err(|err| match err {})
|
||||||
|
}
|
||||||
EncoderBodyProj::Full { body } => {
|
EncoderBodyProj::Full { body } => {
|
||||||
Pin::new(body).poll_next(cx).map_err(|err| match err {})
|
Pin::new(body).poll_next(cx).map_err(|err| match err {})
|
||||||
}
|
}
|
||||||
@ -138,8 +142,8 @@ where
|
|||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
match self {
|
match self {
|
||||||
EncoderBody::None => Ok(Bytes::new()),
|
EncoderBody::None { body } => Ok(body.try_into_bytes().unwrap()),
|
||||||
EncoderBody::Full { body } => Ok(body),
|
EncoderBody::Full { body } => Ok(body.try_into_bytes().unwrap()),
|
||||||
_ => Err(self),
|
_ => Err(self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user