From 2629699b6206997f57872553354c0020adc768c9 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 26 Mar 2019 18:46:06 -0700 Subject: [PATCH] rename flate2-c feature to flate2-zlib --- Cargo.toml | 8 ++++---- actix-http/Cargo.toml | 2 +- actix-http/src/encoding/decoder.rs | 24 ++++++++++++++---------- actix-http/src/encoding/encoder.rs | 22 +++++++++++----------- awc/Cargo.toml | 14 +++++++++++++- src/lib.rs | 2 +- src/middleware/mod.rs | 8 ++++---- 7 files changed, 48 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22c2efe9..363989bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,10 +36,10 @@ members = [ ] [package.metadata.docs.rs] -features = ["ssl", "tls", "rust-tls", "brotli", "flate2-c", "cookies", "client"] +features = ["ssl", "tls", "rust-tls", "brotli", "flate2-zlib", "cookies", "client"] [features] -default = ["brotli", "flate2-c", "cookies", "client"] +default = ["brotli", "flate2-zlib", "cookies", "client"] # http client client = ["awc"] @@ -48,7 +48,7 @@ client = ["awc"] brotli = ["actix-http/brotli2"] # miniz-sys backend for flate2 crate -flate2-c = ["actix-http/flate2-c"] +flate2-zlib = ["actix-http/flate2-zlib"] # rust backend for flate2 crate flate2-rust = ["actix-http/flate2-rust"] @@ -102,7 +102,7 @@ openssl = { version="0.10", optional = true } # rustls = { version = "^0.15", optional = true } [dev-dependencies] -actix-http = { path = "actix-http", features=["ssl", "brotli", "flate2-c"] } +actix-http = { path = "actix-http", features=["ssl", "brotli", "flate2-zlib"] } actix-http-test = { path = "test-server", features=["ssl"] } rand = "0.6" env_logger = "0.6" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 7b73e7e2..427024e2 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -40,7 +40,7 @@ cookies = ["cookie"] brotli = ["brotli2"] # miniz-sys backend for flate2 crate -flate2-c = ["flate2/miniz-sys"] +flate2-zlib = ["flate2/miniz-sys"] # rust backend for flate2 crate flate2-rust = ["flate2/rust_backend"] diff --git a/actix-http/src/encoding/decoder.rs b/actix-http/src/encoding/decoder.rs index a922d173..b4246c64 100644 --- a/actix-http/src/encoding/decoder.rs +++ b/actix-http/src/encoding/decoder.rs @@ -5,7 +5,7 @@ use futures::{Async, Poll, Stream}; #[cfg(feature = "brotli")] use brotli2::write::BrotliDecoder; -#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] use flate2::write::{GzDecoder, ZlibDecoder}; use super::Writer; @@ -27,11 +27,11 @@ where ContentEncoding::Br => Some(ContentDecoder::Br(Box::new( BrotliDecoder::new(Writer::new()), ))), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoding::Deflate => Some(ContentDecoder::Deflate(Box::new( ZlibDecoder::new(Writer::new()), ))), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoding::Gzip => Some(ContentDecoder::Gzip(Box::new( GzDecoder::new(Writer::new()), ))), @@ -95,15 +95,16 @@ where } enum ContentDecoder { - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] Deflate(Box>), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] Gzip(Box>), #[cfg(feature = "brotli")] Br(Box>), } impl ContentDecoder { + #[allow(unreachable_patterns)] fn feed_eof(&mut self) -> io::Result> { match self { #[cfg(feature = "brotli")] @@ -118,7 +119,7 @@ impl ContentDecoder { } Err(e) => Err(e), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentDecoder::Gzip(ref mut decoder) => match decoder.try_finish() { Ok(_) => { let b = decoder.get_mut().take(); @@ -130,7 +131,7 @@ impl ContentDecoder { } Err(e) => Err(e), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentDecoder::Deflate(ref mut decoder) => match decoder.try_finish() { Ok(_) => { let b = decoder.get_mut().take(); @@ -142,12 +143,14 @@ impl ContentDecoder { } Err(e) => Err(e), }, + _ => Ok(None), } } + #[allow(unreachable_patterns)] fn feed_data(&mut self, data: Bytes) -> io::Result> { match self { - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentDecoder::Br(ref mut decoder) => match decoder.write_all(&data) { Ok(_) => { decoder.flush()?; @@ -160,7 +163,7 @@ impl ContentDecoder { } Err(e) => Err(e), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentDecoder::Gzip(ref mut decoder) => match decoder.write_all(&data) { Ok(_) => { decoder.flush()?; @@ -173,7 +176,7 @@ impl ContentDecoder { } Err(e) => Err(e), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentDecoder::Deflate(ref mut decoder) => match decoder.write_all(&data) { Ok(_) => { decoder.flush()?; @@ -186,6 +189,7 @@ impl ContentDecoder { } Err(e) => Err(e), }, + _ => Ok(Some(data)), } } } diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 1985dcdf..0778cc26 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -6,7 +6,7 @@ use futures::{Async, Poll}; #[cfg(feature = "brotli")] use brotli2::write::BrotliEncoder; -#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] +#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] use flate2::write::{GzEncoder, ZlibEncoder}; use crate::body::{Body, BodyLength, MessageBody, ResponseBody}; @@ -142,9 +142,9 @@ fn update_head(encoding: ContentEncoding, head: &mut ResponseHead) { } enum ContentEncoder { - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] Deflate(ZlibEncoder), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] Gzip(GzEncoder), #[cfg(feature = "brotli")] Br(BrotliEncoder), @@ -153,12 +153,12 @@ enum ContentEncoder { impl ContentEncoder { fn encoder(encoding: ContentEncoding) -> Option { match encoding { - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoding::Deflate => Some(ContentEncoder::Deflate(ZlibEncoder::new( Writer::new(), flate2::Compression::fast(), ))), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoding::Gzip => Some(ContentEncoder::Gzip(GzEncoder::new( Writer::new(), flate2::Compression::fast(), @@ -176,9 +176,9 @@ impl ContentEncoder { match *self { #[cfg(feature = "brotli")] ContentEncoder::Br(ref mut encoder) => encoder.get_mut().take(), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(), - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Gzip(ref mut encoder) => encoder.get_mut().take(), } } @@ -190,12 +190,12 @@ impl ContentEncoder { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Gzip(encoder) => match encoder.finish() { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Deflate(encoder) => match encoder.finish() { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), @@ -213,7 +213,7 @@ impl ContentEncoder { Err(err) } }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Gzip(ref mut encoder) => match encoder.write_all(data) { Ok(_) => Ok(!encoder.get_ref().buf.is_empty()), Err(err) => { @@ -221,7 +221,7 @@ impl ContentEncoder { Err(err) } }, - #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] + #[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))] ContentEncoder::Deflate(ref mut encoder) => match encoder.write_all(data) { Ok(_) => Ok(!encoder.get_ref().buf.is_empty()), Err(err) => { diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 023bd088..72b72d36 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -17,8 +17,11 @@ edition = "2018" name = "awc" path = "src/lib.rs" +[package.metadata.docs.rs] +features = ["ssl", "brotli", "flate2-zlib", "cookies"] + [features] -default = ["cookies"] +default = ["cookies", "brotli", "flate2-zlib"] # openssl ssl = ["openssl", "actix-http/ssl"] @@ -26,6 +29,15 @@ ssl = ["openssl", "actix-http/ssl"] # cookies integration cookies = ["cookie", "actix-http/cookies"] +# brotli encoding, requires c compiler +brotli = ["actix-http/brotli2"] + +# miniz-sys backend for flate2 crate +flate2-zlib = ["actix-http/flate2-zlib"] + +# rust backend for flate2 crate +flate2-rust = ["actix-http/flate2-rust"] + [dependencies] actix-service = "0.3.4" actix-http = { path = "../actix-http/" } diff --git a/src/lib.rs b/src/lib.rs index 1bf29213..a21032db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ //! dependency //! * `brotli` - enables `brotli` compression support, requires `c` //! compiler -//! * `flate2-c` - enables `gzip`, `deflate` compression support, requires +//! * `flate2-zlib` - enables `gzip`, `deflate` compression support, requires //! `c` compiler //! * `flate2-rust` - experimental rust based implementation for //! `gzip`, `deflate` compression. diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs index 764cd9a3..aee0ae3d 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -1,12 +1,12 @@ //! Middlewares -#[cfg(any(feature = "brotli", feature = "flate2"))] +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] mod compress; -#[cfg(any(feature = "brotli", feature = "flate2"))] +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] pub use self::compress::Compress; -#[cfg(any(feature = "brotli", feature = "flate2"))] +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] mod decompress; -#[cfg(any(feature = "brotli", feature = "flate2"))] +#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))] pub use self::decompress::Decompress; pub mod cors;