mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
rename flate2-c feature to flate2-zlib
This commit is contained in:
parent
1904b01fc0
commit
2629699b62
@ -36,10 +36,10 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[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]
|
[features]
|
||||||
default = ["brotli", "flate2-c", "cookies", "client"]
|
default = ["brotli", "flate2-zlib", "cookies", "client"]
|
||||||
|
|
||||||
# http client
|
# http client
|
||||||
client = ["awc"]
|
client = ["awc"]
|
||||||
@ -48,7 +48,7 @@ client = ["awc"]
|
|||||||
brotli = ["actix-http/brotli2"]
|
brotli = ["actix-http/brotli2"]
|
||||||
|
|
||||||
# miniz-sys backend for flate2 crate
|
# miniz-sys backend for flate2 crate
|
||||||
flate2-c = ["actix-http/flate2-c"]
|
flate2-zlib = ["actix-http/flate2-zlib"]
|
||||||
|
|
||||||
# rust backend for flate2 crate
|
# rust backend for flate2 crate
|
||||||
flate2-rust = ["actix-http/flate2-rust"]
|
flate2-rust = ["actix-http/flate2-rust"]
|
||||||
@ -102,7 +102,7 @@ openssl = { version="0.10", optional = true }
|
|||||||
# rustls = { version = "^0.15", optional = true }
|
# rustls = { version = "^0.15", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[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"] }
|
actix-http-test = { path = "test-server", features=["ssl"] }
|
||||||
rand = "0.6"
|
rand = "0.6"
|
||||||
env_logger = "0.6"
|
env_logger = "0.6"
|
||||||
|
@ -40,7 +40,7 @@ cookies = ["cookie"]
|
|||||||
brotli = ["brotli2"]
|
brotli = ["brotli2"]
|
||||||
|
|
||||||
# miniz-sys backend for flate2 crate
|
# miniz-sys backend for flate2 crate
|
||||||
flate2-c = ["flate2/miniz-sys"]
|
flate2-zlib = ["flate2/miniz-sys"]
|
||||||
|
|
||||||
# rust backend for flate2 crate
|
# rust backend for flate2 crate
|
||||||
flate2-rust = ["flate2/rust_backend"]
|
flate2-rust = ["flate2/rust_backend"]
|
||||||
|
@ -5,7 +5,7 @@ use futures::{Async, Poll, Stream};
|
|||||||
|
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
use brotli2::write::BrotliDecoder;
|
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 flate2::write::{GzDecoder, ZlibDecoder};
|
||||||
|
|
||||||
use super::Writer;
|
use super::Writer;
|
||||||
@ -27,11 +27,11 @@ where
|
|||||||
ContentEncoding::Br => Some(ContentDecoder::Br(Box::new(
|
ContentEncoding::Br => Some(ContentDecoder::Br(Box::new(
|
||||||
BrotliDecoder::new(Writer::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(
|
ContentEncoding::Deflate => Some(ContentDecoder::Deflate(Box::new(
|
||||||
ZlibDecoder::new(Writer::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(
|
ContentEncoding::Gzip => Some(ContentDecoder::Gzip(Box::new(
|
||||||
GzDecoder::new(Writer::new()),
|
GzDecoder::new(Writer::new()),
|
||||||
))),
|
))),
|
||||||
@ -95,15 +95,16 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum ContentDecoder {
|
enum ContentDecoder {
|
||||||
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
Deflate(Box<ZlibDecoder<Writer>>),
|
Deflate(Box<ZlibDecoder<Writer>>),
|
||||||
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
Gzip(Box<GzDecoder<Writer>>),
|
Gzip(Box<GzDecoder<Writer>>),
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
Br(Box<BrotliDecoder<Writer>>),
|
Br(Box<BrotliDecoder<Writer>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContentDecoder {
|
impl ContentDecoder {
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
fn feed_eof(&mut self) -> io::Result<Option<Bytes>> {
|
fn feed_eof(&mut self) -> io::Result<Option<Bytes>> {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
@ -118,7 +119,7 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
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() {
|
ContentDecoder::Gzip(ref mut decoder) => match decoder.try_finish() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let b = decoder.get_mut().take();
|
let b = decoder.get_mut().take();
|
||||||
@ -130,7 +131,7 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
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() {
|
ContentDecoder::Deflate(ref mut decoder) => match decoder.try_finish() {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let b = decoder.get_mut().take();
|
let b = decoder.get_mut().take();
|
||||||
@ -142,12 +143,14 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
},
|
},
|
||||||
|
_ => Ok(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unreachable_patterns)]
|
||||||
fn feed_data(&mut self, data: Bytes) -> io::Result<Option<Bytes>> {
|
fn feed_data(&mut self, data: Bytes) -> io::Result<Option<Bytes>> {
|
||||||
match self {
|
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) {
|
ContentDecoder::Br(ref mut decoder) => match decoder.write_all(&data) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
decoder.flush()?;
|
decoder.flush()?;
|
||||||
@ -160,7 +163,7 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
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) {
|
ContentDecoder::Gzip(ref mut decoder) => match decoder.write_all(&data) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
decoder.flush()?;
|
decoder.flush()?;
|
||||||
@ -173,7 +176,7 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
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) {
|
ContentDecoder::Deflate(ref mut decoder) => match decoder.write_all(&data) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
decoder.flush()?;
|
decoder.flush()?;
|
||||||
@ -186,6 +189,7 @@ impl ContentDecoder {
|
|||||||
}
|
}
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
},
|
},
|
||||||
|
_ => Ok(Some(data)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ use futures::{Async, Poll};
|
|||||||
|
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
use brotli2::write::BrotliEncoder;
|
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 flate2::write::{GzEncoder, ZlibEncoder};
|
||||||
|
|
||||||
use crate::body::{Body, BodyLength, MessageBody, ResponseBody};
|
use crate::body::{Body, BodyLength, MessageBody, ResponseBody};
|
||||||
@ -142,9 +142,9 @@ fn update_head(encoding: ContentEncoding, head: &mut ResponseHead) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum ContentEncoder {
|
enum ContentEncoder {
|
||||||
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
Deflate(ZlibEncoder<Writer>),
|
Deflate(ZlibEncoder<Writer>),
|
||||||
#[cfg(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
Gzip(GzEncoder<Writer>),
|
Gzip(GzEncoder<Writer>),
|
||||||
#[cfg(feature = "brotli")]
|
#[cfg(feature = "brotli")]
|
||||||
Br(BrotliEncoder<Writer>),
|
Br(BrotliEncoder<Writer>),
|
||||||
@ -153,12 +153,12 @@ enum ContentEncoder {
|
|||||||
impl ContentEncoder {
|
impl ContentEncoder {
|
||||||
fn encoder(encoding: ContentEncoding) -> Option<Self> {
|
fn encoder(encoding: ContentEncoding) -> Option<Self> {
|
||||||
match encoding {
|
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(
|
ContentEncoding::Deflate => Some(ContentEncoder::Deflate(ZlibEncoder::new(
|
||||||
Writer::new(),
|
Writer::new(),
|
||||||
flate2::Compression::fast(),
|
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(
|
ContentEncoding::Gzip => Some(ContentEncoder::Gzip(GzEncoder::new(
|
||||||
Writer::new(),
|
Writer::new(),
|
||||||
flate2::Compression::fast(),
|
flate2::Compression::fast(),
|
||||||
@ -176,9 +176,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(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(),
|
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(),
|
ContentEncoder::Gzip(ref mut encoder) => encoder.get_mut().take(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,12 +190,12 @@ impl ContentEncoder {
|
|||||||
Ok(writer) => Ok(writer.buf.freeze()),
|
Ok(writer) => Ok(writer.buf.freeze()),
|
||||||
Err(err) => Err(err),
|
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() {
|
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(any(feature = "flate2-c", feature = "flate2-rust"))]
|
#[cfg(any(feature = "flate2-zlib", 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),
|
||||||
@ -213,7 +213,7 @@ impl ContentEncoder {
|
|||||||
Err(err)
|
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) {
|
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) => {
|
||||||
@ -221,7 +221,7 @@ impl ContentEncoder {
|
|||||||
Err(err)
|
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) {
|
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) => {
|
||||||
|
@ -17,8 +17,11 @@ edition = "2018"
|
|||||||
name = "awc"
|
name = "awc"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
features = ["ssl", "brotli", "flate2-zlib", "cookies"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["cookies"]
|
default = ["cookies", "brotli", "flate2-zlib"]
|
||||||
|
|
||||||
# openssl
|
# openssl
|
||||||
ssl = ["openssl", "actix-http/ssl"]
|
ssl = ["openssl", "actix-http/ssl"]
|
||||||
@ -26,6 +29,15 @@ ssl = ["openssl", "actix-http/ssl"]
|
|||||||
# cookies integration
|
# cookies integration
|
||||||
cookies = ["cookie", "actix-http/cookies"]
|
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]
|
[dependencies]
|
||||||
actix-service = "0.3.4"
|
actix-service = "0.3.4"
|
||||||
actix-http = { path = "../actix-http/" }
|
actix-http = { path = "../actix-http/" }
|
||||||
|
@ -71,7 +71,7 @@
|
|||||||
//! dependency
|
//! dependency
|
||||||
//! * `brotli` - enables `brotli` compression support, requires `c`
|
//! * `brotli` - enables `brotli` compression support, requires `c`
|
||||||
//! compiler
|
//! compiler
|
||||||
//! * `flate2-c` - enables `gzip`, `deflate` compression support, requires
|
//! * `flate2-zlib` - enables `gzip`, `deflate` compression support, requires
|
||||||
//! `c` compiler
|
//! `c` compiler
|
||||||
//! * `flate2-rust` - experimental rust based implementation for
|
//! * `flate2-rust` - experimental rust based implementation for
|
||||||
//! `gzip`, `deflate` compression.
|
//! `gzip`, `deflate` compression.
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
//! Middlewares
|
//! Middlewares
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
mod compress;
|
mod compress;
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
pub use self::compress::Compress;
|
pub use self::compress::Compress;
|
||||||
|
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
mod decompress;
|
mod decompress;
|
||||||
#[cfg(any(feature = "brotli", feature = "flate2"))]
|
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||||
pub use self::decompress::Decompress;
|
pub use self::decompress::Decompress;
|
||||||
|
|
||||||
pub mod cors;
|
pub mod cors;
|
||||||
|
Loading…
Reference in New Issue
Block a user