mirror of
https://github.com/actix/actix-web.git
synced 2025-04-08 02:49:52 +00:00
Switch to a rustified version of brotli.
This commit is contained in:
parent
4921243add
commit
3d98768093
6 changed files with 27 additions and 23 deletions
|
@ -48,7 +48,7 @@ default = ["brotli", "flate2-zlib", "client", "fail"]
|
|||
# http client
|
||||
client = ["awc"]
|
||||
|
||||
# brotli encoding, requires c compiler
|
||||
# brotli encoding
|
||||
brotli = ["actix-http/brotli", "awc/brotli"]
|
||||
|
||||
# miniz-sys backend for flate2 crate
|
||||
|
@ -111,7 +111,7 @@ actix-http-test = "1.0.0-alpha.3"
|
|||
rand = "0.7"
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
brotli2 = "0.3.2"
|
||||
brotli2 = { package = "brotli", version = "3.3.0" }
|
||||
flate2 = "1.0.2"
|
||||
|
||||
[profile.release]
|
||||
|
|
|
@ -31,7 +31,7 @@ openssl = ["actix-tls/openssl", "actix-connect/openssl"]
|
|||
# rustls support
|
||||
rustls = ["actix-tls/rustls", "actix-connect/rustls"]
|
||||
|
||||
# brotli encoding, requires c compiler
|
||||
# brotli encoding
|
||||
brotli = ["brotli2"]
|
||||
|
||||
# miniz-sys backend for flate2 crate
|
||||
|
@ -88,7 +88,7 @@ time = "0.1.42"
|
|||
ring = { version = "0.16.9", optional = true }
|
||||
|
||||
# compression
|
||||
brotli2 = { version="0.3.2", optional = true }
|
||||
brotli2 = { package = "brotli", version="3.3.0", optional = true }
|
||||
flate2 = { version="1.0.7", optional = true, default-features = false }
|
||||
|
||||
# optional deps
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::task::{Context, Poll};
|
|||
|
||||
use actix_threadpool::{run, CpuFuture};
|
||||
#[cfg(feature = "brotli")]
|
||||
use brotli2::write::BrotliDecoder;
|
||||
use brotli2::DecompressorWriter;
|
||||
use bytes::Bytes;
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
use flate2::write::{GzDecoder, ZlibDecoder};
|
||||
|
@ -34,7 +34,7 @@ where
|
|||
let decoder = match encoding {
|
||||
#[cfg(feature = "brotli")]
|
||||
ContentEncoding::Br => Some(ContentDecoder::Br(Box::new(
|
||||
BrotliDecoder::new(Writer::new()),
|
||||
DecompressorWriter::new(Writer::new(), 0),
|
||||
))),
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
ContentEncoding::Deflate => Some(ContentDecoder::Deflate(Box::new(
|
||||
|
@ -145,7 +145,7 @@ enum ContentDecoder {
|
|||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
Gzip(Box<GzDecoder<Writer>>),
|
||||
#[cfg(feature = "brotli")]
|
||||
Br(Box<BrotliDecoder<Writer>>),
|
||||
Br(Box<DecompressorWriter<Writer>>),
|
||||
}
|
||||
|
||||
impl ContentDecoder {
|
||||
|
@ -153,9 +153,9 @@ impl ContentDecoder {
|
|||
fn feed_eof(&mut self) -> io::Result<Option<Bytes>> {
|
||||
match self {
|
||||
#[cfg(feature = "brotli")]
|
||||
ContentDecoder::Br(ref mut decoder) => match decoder.finish() {
|
||||
Ok(mut writer) => {
|
||||
let b = writer.take();
|
||||
ContentDecoder::Br(ref mut decoder) => match decoder.flush() {
|
||||
Ok(()) => {
|
||||
let b = decoder.get_mut().take();
|
||||
if !b.is_empty() {
|
||||
Ok(Some(b))
|
||||
} else {
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::task::{Context, Poll};
|
|||
|
||||
use actix_threadpool::{run, CpuFuture};
|
||||
#[cfg(feature = "brotli")]
|
||||
use brotli2::write::BrotliEncoder;
|
||||
use brotli2::CompressorWriter;
|
||||
use bytes::Bytes;
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
use flate2::write::{GzEncoder, ZlibEncoder};
|
||||
|
@ -178,7 +178,7 @@ enum ContentEncoder {
|
|||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
Gzip(GzEncoder<Writer>),
|
||||
#[cfg(feature = "brotli")]
|
||||
Br(BrotliEncoder<Writer>),
|
||||
Br(CompressorWriter<Writer>),
|
||||
}
|
||||
|
||||
impl ContentEncoder {
|
||||
|
@ -195,9 +195,12 @@ impl ContentEncoder {
|
|||
flate2::Compression::fast(),
|
||||
))),
|
||||
#[cfg(feature = "brotli")]
|
||||
ContentEncoding::Br => {
|
||||
Some(ContentEncoder::Br(BrotliEncoder::new(Writer::new(), 3)))
|
||||
}
|
||||
ContentEncoding::Br => Some(ContentEncoder::Br(CompressorWriter::new(
|
||||
Writer::new(),
|
||||
0,
|
||||
3,
|
||||
0,
|
||||
))),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +209,11 @@ impl ContentEncoder {
|
|||
pub(crate) fn take(&mut self) -> Bytes {
|
||||
match *self {
|
||||
#[cfg(feature = "brotli")]
|
||||
ContentEncoder::Br(ref mut encoder) => encoder.get_mut().take(),
|
||||
ContentEncoder::Br(ref mut encoder) => {
|
||||
let mut encoder_new = CompressorWriter::new(Writer::new(), 0, 3, 0);
|
||||
std::mem::swap(encoder, &mut encoder_new);
|
||||
encoder_new.into_inner().take()
|
||||
}
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(),
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
|
@ -217,10 +224,7 @@ impl ContentEncoder {
|
|||
fn finish(self) -> Result<Bytes, io::Error> {
|
||||
match self {
|
||||
#[cfg(feature = "brotli")]
|
||||
ContentEncoder::Br(encoder) => match encoder.finish() {
|
||||
Ok(writer) => Ok(writer.buf.freeze()),
|
||||
Err(err) => Err(err),
|
||||
},
|
||||
ContentEncoder::Br(encoder) => Ok(encoder.into_inner().buf.freeze()),
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
ContentEncoder::Gzip(encoder) => match encoder.finish() {
|
||||
Ok(writer) => Ok(writer.buf.freeze()),
|
||||
|
|
|
@ -32,7 +32,7 @@ openssl = ["open-ssl", "actix-http/openssl"]
|
|||
# rustls
|
||||
rustls = ["rust-tls", "actix-http/rustls"]
|
||||
|
||||
# brotli encoding, requires c compiler
|
||||
# brotli encoding
|
||||
brotli = ["actix-http/brotli"]
|
||||
|
||||
# miniz-sys backend for flate2 crate
|
||||
|
@ -69,7 +69,7 @@ actix-http-test = { version = "1.0.0-alpha.3", features=["openssl"] }
|
|||
actix-utils = "1.0.0-alpha.3"
|
||||
actix-server = { version = "1.0.0-alpha.3" }
|
||||
actix-tls = { version = "1.0.0-alpha.3", features=["openssl", "rustls"] }
|
||||
brotli2 = { version="0.3.2" }
|
||||
brotli2 = { package = "brotli", version="3.3.0" }
|
||||
flate2 = { version="1.0.2" }
|
||||
env_logger = "0.6"
|
||||
webpki = { version = "0.21" }
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
//! * `rustls` - enables ssl support via `rustls` crate, supports `http/2`
|
||||
//! * `secure-cookies` - enables secure cookies support, includes `ring` crate as
|
||||
//! dependency
|
||||
//! * `brotli` - enables `brotli` compression support, requires `c`
|
||||
//! * `brotli` - enables `brotli` compression support
|
||||
//! compiler (default enabled)
|
||||
//! * `flate2-zlib` - enables `gzip`, `deflate` compression support, requires
|
||||
//! `c` compiler (default enabled)
|
||||
|
|
Loading…
Reference in a new issue