From 307b2e5b0e2732a600ca6d34df18a2559ded0c03 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 24 Mar 2019 11:29:35 -0700 Subject: [PATCH] fix compress features --- .travis.yml | 6 +++--- src/app.rs | 2 +- src/middleware/compress.rs | 29 ++++++++++++++++------------- src/middleware/mod.rs | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9caaac1b..061c8b8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,13 +35,13 @@ before_script: script: - cargo clean - - cargo test --all -- --nocapture + - cargo test --all-features --all -- --nocapture # Upload docs after_success: - | if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then - cargo doc --no-deps && + cargo doc --all-features --no-deps && echo "" > target/doc/index.html && git clone https://github.com/davisp/ghp-import.git && ./ghp-import/ghp_import.py -n -p -f -m "Documentation upload" -r https://"$GH_TOKEN"@github.com/"$TRAVIS_REPO_SLUG.git" target/doc && @@ -49,7 +49,7 @@ after_success: fi - | if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-03-02" ]]; then - taskset -c 0 cargo tarpaulin --out Xml --all + taskset -c 0 cargo tarpaulin --out Xml --all --all-features bash <(curl -s https://codecov.io/bash) echo "Uploaded code coverage" fi diff --git a/src/app.rs b/src/app.rs index c4f2e33b..991288dd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -361,7 +361,7 @@ where } } - /// Default resource to be used if no matching route could be found. + /// Default resource to be used if no matching resource could be found. pub fn default_resource(mut self, f: F) -> Self where F: FnOnce(Resource

) -> Resource, diff --git a/src/middleware/compress.rs b/src/middleware/compress.rs index b3880a53..3c4718fe 100644 --- a/src/middleware/compress.rs +++ b/src/middleware/compress.rs @@ -1,3 +1,4 @@ +/// `Middleware` for compressing response body. use std::io::Write; use std::marker::PhantomData; use std::str::FromStr; @@ -17,15 +18,17 @@ use log::trace; #[cfg(feature = "brotli")] use brotli2::write::BrotliEncoder; -#[cfg(feature = "flate2")] +#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] use flate2::write::{GzEncoder, ZlibEncoder}; use crate::service::{ServiceRequest, ServiceResponse}; #[derive(Debug, Clone)] +/// `Middleware` for compressing response body. pub struct Compress(ContentEncoding); impl Compress { + /// Create new `Compress` middleware with default encoding. pub fn new(encoding: ContentEncoding) -> Self { Compress(encoding) } @@ -283,9 +286,9 @@ impl io::Write for Writer { } pub(crate) enum ContentEncoder { - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] Deflate(ZlibEncoder), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] Gzip(GzEncoder), #[cfg(feature = "brotli")] Br(BrotliEncoder), @@ -296,9 +299,9 @@ impl fmt::Debug for ContentEncoder { match *self { #[cfg(feature = "brotli")] ContentEncoder::Br(_) => writeln!(f, "ContentEncoder(Brotli)"), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Deflate(_) => writeln!(f, "ContentEncoder(Deflate)"), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Gzip(_) => writeln!(f, "ContentEncoder(Gzip)"), } } @@ -307,12 +310,12 @@ impl fmt::Debug for ContentEncoder { impl ContentEncoder { fn encoder(encoding: ContentEncoding) -> Option { match encoding { - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoding::Deflate => Some(ContentEncoder::Deflate(ZlibEncoder::new( Writer::new(), flate2::Compression::fast(), ))), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoding::Gzip => Some(ContentEncoder::Gzip(GzEncoder::new( Writer::new(), flate2::Compression::fast(), @@ -330,9 +333,9 @@ impl ContentEncoder { match *self { #[cfg(feature = "brotli")] ContentEncoder::Br(ref mut encoder) => encoder.get_mut().take(), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(), - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Gzip(ref mut encoder) => encoder.get_mut().take(), } } @@ -344,12 +347,12 @@ impl ContentEncoder { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), }, - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Gzip(encoder) => match encoder.finish() { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), }, - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Deflate(encoder) => match encoder.finish() { Ok(writer) => Ok(writer.buf.freeze()), Err(err) => Err(err), @@ -367,7 +370,7 @@ impl ContentEncoder { Err(err) } }, - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", feature = "flate2-rust"))] ContentEncoder::Gzip(ref mut encoder) => match encoder.write_all(data) { Ok(_) => Ok(!encoder.get_ref().buf.is_empty()), Err(err) => { @@ -375,7 +378,7 @@ impl ContentEncoder { Err(err) } }, - #[cfg(feature = "flate2")] + #[cfg(any(feature = "flate2-c", 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/src/middleware/mod.rs b/src/middleware/mod.rs index b997cca2..e984b1d8 100644 --- a/src/middleware/mod.rs +++ b/src/middleware/mod.rs @@ -1,3 +1,4 @@ +//! Middlewares #[cfg(any(feature = "brotli", feature = "flate2"))] mod compress; #[cfg(any(feature = "brotli", feature = "flate2"))]