diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 2e9af5462..4fd2123f6 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -1,7 +1,6 @@ //! Stream encoders. use std::{ - error::Error as StdError, future::Future, io::{self, Write as _}, pin::Pin, @@ -10,7 +9,6 @@ use std::{ use actix_rt::task::{spawn_blocking, JoinHandle}; use bytes::Bytes; -use derive_more::Display; use futures_core::ready; use pin_project_lite::pin_project; @@ -23,7 +21,7 @@ use flate2::write::{GzEncoder, ZlibEncoder}; #[cfg(feature = "compress-zstd")] use zstd::stream::write::Encoder as ZstdEncoder; -use super::Writer; +use super::{EncoderError, Writer}; use crate::{ body::{BodySize, MessageBody}, error::BlockingError, @@ -364,32 +362,3 @@ impl ContentEncoder { } } } - -#[derive(Debug, Display)] -#[non_exhaustive] -pub enum EncoderError { - #[display(fmt = "body")] - Body(Box), - - #[display(fmt = "blocking")] - Blocking(BlockingError), - - #[display(fmt = "io")] - Io(io::Error), -} - -impl StdError for EncoderError { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - match self { - EncoderError::Body(err) => Some(&**err), - EncoderError::Blocking(err) => Some(err), - EncoderError::Io(err) => Some(err), - } - } -} - -impl From for crate::Error { - fn from(err: EncoderError) -> Self { - crate::Error::new_encoder().with_cause(err) - } -} diff --git a/actix-http/src/encoding/mod.rs b/actix-http/src/encoding/mod.rs index 261abc9f3..b671572b6 100644 --- a/actix-http/src/encoding/mod.rs +++ b/actix-http/src/encoding/mod.rs @@ -1,22 +1,60 @@ //! Content-Encoding support. -use std::io; +use std::{error::Error as StdError, io}; use bytes::{Bytes, BytesMut}; +use derive_more::Display; +use crate::error::BlockingError; + +#[cfg(feature = "__compress")] mod decoder; +#[cfg(feature = "__compress")] mod encoder; +#[cfg(feature = "__compress")] pub use self::decoder::Decoder; -pub use self::encoder::{Encoder, EncoderError}; +#[cfg(feature = "__compress")] +pub use self::encoder::Encoder; + +#[derive(Debug, Display)] +#[non_exhaustive] +pub enum EncoderError { + #[display(fmt = "body")] + Body(Box), + + #[display(fmt = "blocking")] + Blocking(BlockingError), + + #[display(fmt = "io")] + Io(io::Error), +} + +impl StdError for EncoderError { + fn source(&self) -> Option<&(dyn StdError + 'static)> { + match self { + EncoderError::Body(err) => Some(&**err), + EncoderError::Blocking(err) => Some(err), + EncoderError::Io(err) => Some(err), + } + } +} + +impl From for crate::Error { + fn from(err: EncoderError) -> Self { + crate::Error::new_encoder().with_cause(err) + } +} /// Special-purpose writer for streaming (de-)compression. /// /// Pre-allocates 8KiB of capacity. +#[cfg(feature = "__compress")] pub(self) struct Writer { buf: BytesMut, } +#[cfg(feature = "__compress")] impl Writer { fn new() -> Writer { Writer { @@ -29,6 +67,7 @@ impl Writer { } } +#[cfg(feature = "__compress")] impl io::Write for Writer { fn write(&mut self, buf: &[u8]) -> io::Result { self.buf.extend_from_slice(buf); diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index 60dc26f0f..6e305cb9b 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -32,7 +32,6 @@ pub mod body; mod builder; mod config; -#[cfg(feature = "__compress")] pub mod encoding; mod extensions; pub mod header;