mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-28 01:52:57 +01:00
fix compress features
This commit is contained in:
parent
bc01d39d4d
commit
307b2e5b0e
@ -35,13 +35,13 @@ before_script:
|
|||||||
|
|
||||||
script:
|
script:
|
||||||
- cargo clean
|
- cargo clean
|
||||||
- cargo test --all -- --nocapture
|
- cargo test --all-features --all -- --nocapture
|
||||||
|
|
||||||
# Upload docs
|
# Upload docs
|
||||||
after_success:
|
after_success:
|
||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_OS_NAME" == "linux" && "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_RUST_VERSION" == "stable" ]]; then
|
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 "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
echo "<meta http-equiv=refresh content=0;url=os_balloon/index.html>" > target/doc/index.html &&
|
||||||
git clone https://github.com/davisp/ghp-import.git &&
|
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 &&
|
./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
|
fi
|
||||||
- |
|
- |
|
||||||
if [[ "$TRAVIS_RUST_VERSION" == "nightly-2019-03-02" ]]; then
|
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)
|
bash <(curl -s https://codecov.io/bash)
|
||||||
echo "Uploaded code coverage"
|
echo "Uploaded code coverage"
|
||||||
fi
|
fi
|
||||||
|
@ -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<F, U>(mut self, f: F) -> Self
|
pub fn default_resource<F, U>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
/// `Middleware` for compressing response body.
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@ -17,15 +18,17 @@ use log::trace;
|
|||||||
|
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
use brotli2::write::BrotliEncoder;
|
use brotli2::write::BrotliEncoder;
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
use flate2::write::{GzEncoder, ZlibEncoder};
|
use flate2::write::{GzEncoder, ZlibEncoder};
|
||||||
|
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
/// `Middleware` for compressing response body.
|
||||||
pub struct Compress(ContentEncoding);
|
pub struct Compress(ContentEncoding);
|
||||||
|
|
||||||
impl Compress {
|
impl Compress {
|
||||||
|
/// Create new `Compress` middleware with default encoding.
|
||||||
pub fn new(encoding: ContentEncoding) -> Self {
|
pub fn new(encoding: ContentEncoding) -> Self {
|
||||||
Compress(encoding)
|
Compress(encoding)
|
||||||
}
|
}
|
||||||
@ -283,9 +286,9 @@ impl io::Write for Writer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) enum ContentEncoder {
|
pub(crate) enum ContentEncoder {
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
Deflate(ZlibEncoder<Writer>),
|
Deflate(ZlibEncoder<Writer>),
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
Gzip(GzEncoder<Writer>),
|
Gzip(GzEncoder<Writer>),
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
Br(BrotliEncoder<Writer>),
|
Br(BrotliEncoder<Writer>),
|
||||||
@ -296,9 +299,9 @@ impl fmt::Debug for ContentEncoder {
|
|||||||
match *self {
|
match *self {
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
ContentEncoder::Br(_) => writeln!(f, "ContentEncoder(Brotli)"),
|
ContentEncoder::Br(_) => writeln!(f, "ContentEncoder(Brotli)"),
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Deflate(_) => writeln!(f, "ContentEncoder(Deflate)"),
|
ContentEncoder::Deflate(_) => writeln!(f, "ContentEncoder(Deflate)"),
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Gzip(_) => writeln!(f, "ContentEncoder(Gzip)"),
|
ContentEncoder::Gzip(_) => writeln!(f, "ContentEncoder(Gzip)"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,12 +310,12 @@ impl fmt::Debug for ContentEncoder {
|
|||||||
impl ContentEncoder {
|
impl ContentEncoder {
|
||||||
fn encoder(encoding: ContentEncoding) -> Option<Self> {
|
fn encoder(encoding: ContentEncoding) -> Option<Self> {
|
||||||
match encoding {
|
match encoding {
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoding::Deflate => Some(ContentEncoder::Deflate(ZlibEncoder::new(
|
ContentEncoding::Deflate => Some(ContentEncoder::Deflate(ZlibEncoder::new(
|
||||||
Writer::new(),
|
Writer::new(),
|
||||||
flate2::Compression::fast(),
|
flate2::Compression::fast(),
|
||||||
))),
|
))),
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoding::Gzip => Some(ContentEncoder::Gzip(GzEncoder::new(
|
ContentEncoding::Gzip => Some(ContentEncoder::Gzip(GzEncoder::new(
|
||||||
Writer::new(),
|
Writer::new(),
|
||||||
flate2::Compression::fast(),
|
flate2::Compression::fast(),
|
||||||
@ -330,9 +333,9 @@ impl ContentEncoder {
|
|||||||
match *self {
|
match *self {
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
ContentEncoder::Br(ref mut encoder) => encoder.get_mut().take(),
|
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(),
|
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(),
|
ContentEncoder::Gzip(ref mut encoder) => encoder.get_mut().take(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,12 +347,12 @@ impl ContentEncoder {
|
|||||||
Ok(writer) => Ok(writer.buf.freeze()),
|
Ok(writer) => Ok(writer.buf.freeze()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Gzip(encoder) => match encoder.finish() {
|
ContentEncoder::Gzip(encoder) => match encoder.finish() {
|
||||||
Ok(writer) => Ok(writer.buf.freeze()),
|
Ok(writer) => Ok(writer.buf.freeze()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Deflate(encoder) => match encoder.finish() {
|
ContentEncoder::Deflate(encoder) => match encoder.finish() {
|
||||||
Ok(writer) => Ok(writer.buf.freeze()),
|
Ok(writer) => Ok(writer.buf.freeze()),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
@ -367,7 +370,7 @@ impl ContentEncoder {
|
|||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Gzip(ref mut encoder) => match encoder.write_all(data) {
|
ContentEncoder::Gzip(ref mut encoder) => match encoder.write_all(data) {
|
||||||
Ok(_) => Ok(!encoder.get_ref().buf.is_empty()),
|
Ok(_) => Ok(!encoder.get_ref().buf.is_empty()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -375,7 +378,7 @@ impl ContentEncoder {
|
|||||||
Err(err)
|
Err(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
#[cfg(feature = "flate2")]
|
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Deflate(ref mut encoder) => match encoder.write_all(data) {
|
ContentEncoder::Deflate(ref mut encoder) => match encoder.write_all(data) {
|
||||||
Ok(_) => Ok(!encoder.get_ref().buf.is_empty()),
|
Ok(_) => Ok(!encoder.get_ref().buf.is_empty()),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
//! Middlewares
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
mod compress;
|
mod compress;
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
||||||
|
Loading…
Reference in New Issue
Block a user