update brotli crate to 3.3.3

This commit is contained in:
Rob Ede 2022-01-15 13:09:13 +00:00
parent 1505730684
commit 984238dc70
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
7 changed files with 26 additions and 22 deletions

View File

@ -109,7 +109,7 @@ actix-files = "0.6.0-beta.14"
actix-test = { version = "0.1.0-beta.11", features = ["openssl", "rustls"] } actix-test = { version = "0.1.0-beta.11", features = ["openssl", "rustls"] }
awc = { version = "3.0.0-beta.18", features = ["openssl"] } awc = { version = "3.0.0-beta.18", features = ["openssl"] }
brotli2 = "0.3.3" brotli = "3.3.3"
const-str = "0.3" const-str = "0.3"
criterion = { version = "0.3", features = ["html_reports"] } criterion = { version = "0.3", features = ["html_reports"] }
env_logger = "0.9" env_logger = "0.9"
@ -144,8 +144,6 @@ actix-web-actors = { path = "actix-web-actors" }
actix-web-codegen = { path = "actix-web-codegen" } actix-web-codegen = { path = "actix-web-codegen" }
awc = { path = "awc" } awc = { path = "awc" }
brotli = { path = "../rust-brotli" }
# uncomment for quick testing against local actix-net repo # uncomment for quick testing against local actix-net repo
# actix-service = { path = "../actix-net/actix-service" } # actix-service = { path = "../actix-net/actix-service" }
# actix-macros = { path = "../actix-net/actix-macros" } # actix-macros = { path = "../actix-net/actix-macros" }

View File

@ -74,7 +74,7 @@ smallvec = "1.6.1"
actix-tls = { version = "3.0.0", default-features = false, optional = true } actix-tls = { version = "3.0.0", default-features = false, optional = true }
# compression # compression
brotli = { version = "3.3", optional = true } brotli = { version = "3.3.3", optional = true }
flate2 = { version = "1.0.13", optional = true } flate2 = { version = "1.0.13", optional = true }
zstd = { version = "0.9", optional = true } zstd = { version = "0.9", optional = true }

View File

@ -44,7 +44,7 @@ where
pub fn new(stream: S, encoding: ContentEncoding) -> Decoder<S> { pub fn new(stream: S, encoding: ContentEncoding) -> Decoder<S> {
let decoder = match encoding { let decoder = match encoding {
#[cfg(feature = "compress-brotli")] #[cfg(feature = "compress-brotli")]
ContentEncoding::Br => Some(ContentDecoder::Brotli(Box::new( ContentEncoding::Brotli => Some(ContentDecoder::Brotli(Box::new(
brotli::DecompressorWriter::new(Writer::new(), 8_096), brotli::DecompressorWriter::new(Writer::new(), 8_096),
))), ))),
#[cfg(feature = "compress-gzip")] #[cfg(feature = "compress-gzip")]

View File

@ -4,7 +4,6 @@ use std::{
error::Error as StdError, error::Error as StdError,
future::Future, future::Future,
io::{self, Write as _}, io::{self, Write as _},
mem,
pin::Pin, pin::Pin,
task::{Context, Poll}, task::{Context, Poll},
}; };
@ -290,7 +289,7 @@ impl ContentEncoder {
))), ))),
#[cfg(feature = "compress-brotli")] #[cfg(feature = "compress-brotli")]
ContentEncoding::Brotli => Some(ContentEncoder::Br(new_brotli_compressor())), ContentEncoding::Brotli => Some(ContentEncoder::Brotli(new_brotli_compressor())),
#[cfg(feature = "compress-zstd")] #[cfg(feature = "compress-zstd")]
ContentEncoding::Zstd => { ContentEncoding::Zstd => {
@ -306,12 +305,7 @@ impl ContentEncoder {
pub(crate) fn take(&mut self) -> Bytes { pub(crate) fn take(&mut self) -> Bytes {
match *self { match *self {
#[cfg(feature = "compress-brotli")] #[cfg(feature = "compress-brotli")]
// ContentEncoder::Br(ref mut encoder) => encoder.get_mut().take(), ContentEncoder::Brotli(ref mut encoder) => encoder.get_mut().take(),
ContentEncoder::Brotli(ref mut encoder) => {
// `CompressorWriter` has no `get_mut` (yet)
let prev = mem::replace(encoder, new_brotli_compressor());
prev.into_inner().buf.freeze()
}
#[cfg(feature = "compress-gzip")] #[cfg(feature = "compress-gzip")]
ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(), ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(),

View File

@ -101,7 +101,7 @@ actix-tls = { version = "3.0.0", features = ["openssl", "rustls"] }
actix-utils = "3.0.0" actix-utils = "3.0.0"
actix-web = { version = "4.0.0-beta.20", features = ["openssl"] } actix-web = { version = "4.0.0-beta.20", features = ["openssl"] }
brotli2 = "0.3.3" brotli = "3.3.3"
const-str = "0.3" const-str = "0.3"
env_logger = "0.9" env_logger = "0.9"
flate2 = "1.0.13" flate2 = "1.0.13"

View File

@ -41,16 +41,22 @@ pub mod deflate {
pub mod brotli { pub mod brotli {
use super::*; use super::*;
use ::brotli2::{read::BrotliDecoder, write::BrotliEncoder}; use ::brotli::{reader::Decompressor as BrotliDecoder, CompressorWriter as BrotliEncoder};
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> { pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut encoder = BrotliEncoder::new(Vec::new(), 3); let mut encoder = BrotliEncoder::new(
Vec::new(),
8 * 1024, // 32 KiB buffer
3, // BROTLI_PARAM_QUALITY
22, // BROTLI_PARAM_LGWIN
);
encoder.write_all(bytes.as_ref()).unwrap(); encoder.write_all(bytes.as_ref()).unwrap();
encoder.finish().unwrap() encoder.flush().unwrap();
encoder.into_inner()
} }
pub fn decode(bytes: impl AsRef<[u8]>) -> Vec<u8> { pub fn decode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut decoder = BrotliDecoder::new(bytes.as_ref()); let mut decoder = BrotliDecoder::new(bytes.as_ref(), 8_096);
let mut buf = Vec::new(); let mut buf = Vec::new();
decoder.read_to_end(&mut buf).unwrap(); decoder.read_to_end(&mut buf).unwrap();
buf buf

View File

@ -41,16 +41,22 @@ pub mod deflate {
pub mod brotli { pub mod brotli {
use super::*; use super::*;
use ::brotli2::{read::BrotliDecoder, write::BrotliEncoder}; use ::brotli::{reader::Decompressor as BrotliDecoder, CompressorWriter as BrotliEncoder};
pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> { pub fn encode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut encoder = BrotliEncoder::new(Vec::new(), 3); let mut encoder = BrotliEncoder::new(
Vec::new(),
8 * 1024, // 32 KiB buffer
3, // BROTLI_PARAM_QUALITY
22, // BROTLI_PARAM_LGWIN
);
encoder.write_all(bytes.as_ref()).unwrap(); encoder.write_all(bytes.as_ref()).unwrap();
encoder.finish().unwrap() encoder.flush().unwrap();
encoder.into_inner()
} }
pub fn decode(bytes: impl AsRef<[u8]>) -> Vec<u8> { pub fn decode(bytes: impl AsRef<[u8]>) -> Vec<u8> {
let mut decoder = BrotliDecoder::new(bytes.as_ref()); let mut decoder = BrotliDecoder::new(bytes.as_ref(), 8_096);
let mut buf = Vec::new(); let mut buf = Vec::new();
decoder.read_to_end(&mut buf).unwrap(); decoder.read_to_end(&mut buf).unwrap();
buf buf