From 984238dc70f0b68fad0ee1b658f2b23cd0e781dc Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 15 Jan 2022 13:09:13 +0000 Subject: [PATCH] update brotli crate to 3.3.3 --- Cargo.toml | 4 +--- actix-http/Cargo.toml | 2 +- actix-http/src/encoding/decoder.rs | 2 +- actix-http/src/encoding/encoder.rs | 10 ++-------- awc/Cargo.toml | 2 +- awc/tests/utils.rs | 14 ++++++++++---- tests/utils.rs | 14 ++++++++++---- 7 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 39843bc1a..39f2ac32a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,7 +109,7 @@ actix-files = "0.6.0-beta.14" actix-test = { version = "0.1.0-beta.11", features = ["openssl", "rustls"] } awc = { version = "3.0.0-beta.18", features = ["openssl"] } -brotli2 = "0.3.3" +brotli = "3.3.3" const-str = "0.3" criterion = { version = "0.3", features = ["html_reports"] } env_logger = "0.9" @@ -144,8 +144,6 @@ actix-web-actors = { path = "actix-web-actors" } actix-web-codegen = { path = "actix-web-codegen" } awc = { path = "awc" } -brotli = { path = "../rust-brotli" } - # uncomment for quick testing against local actix-net repo # actix-service = { path = "../actix-net/actix-service" } # actix-macros = { path = "../actix-net/actix-macros" } diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 8831b5e5e..df9e11419 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -74,7 +74,7 @@ smallvec = "1.6.1" actix-tls = { version = "3.0.0", default-features = false, optional = true } # compression -brotli = { version = "3.3", optional = true } +brotli = { version = "3.3.3", optional = true } flate2 = { version = "1.0.13", optional = true } zstd = { version = "0.9", optional = true } diff --git a/actix-http/src/encoding/decoder.rs b/actix-http/src/encoding/decoder.rs index dd756ae82..2ed7be899 100644 --- a/actix-http/src/encoding/decoder.rs +++ b/actix-http/src/encoding/decoder.rs @@ -44,7 +44,7 @@ where pub fn new(stream: S, encoding: ContentEncoding) -> Decoder { let decoder = match encoding { #[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), ))), #[cfg(feature = "compress-gzip")] diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs index 257c18318..9696da6f1 100644 --- a/actix-http/src/encoding/encoder.rs +++ b/actix-http/src/encoding/encoder.rs @@ -4,7 +4,6 @@ use std::{ error::Error as StdError, future::Future, io::{self, Write as _}, - mem, pin::Pin, task::{Context, Poll}, }; @@ -290,7 +289,7 @@ impl ContentEncoder { ))), #[cfg(feature = "compress-brotli")] - ContentEncoding::Brotli => Some(ContentEncoder::Br(new_brotli_compressor())), + ContentEncoding::Brotli => Some(ContentEncoder::Brotli(new_brotli_compressor())), #[cfg(feature = "compress-zstd")] ContentEncoding::Zstd => { @@ -306,12 +305,7 @@ impl ContentEncoder { pub(crate) fn take(&mut self) -> Bytes { match *self { #[cfg(feature = "compress-brotli")] - // ContentEncoder::Br(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() - } + ContentEncoder::Brotli(ref mut encoder) => encoder.get_mut().take(), #[cfg(feature = "compress-gzip")] ContentEncoder::Deflate(ref mut encoder) => encoder.get_mut().take(), diff --git a/awc/Cargo.toml b/awc/Cargo.toml index 979166d2d..16c2083d8 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -101,7 +101,7 @@ actix-tls = { version = "3.0.0", features = ["openssl", "rustls"] } actix-utils = "3.0.0" actix-web = { version = "4.0.0-beta.20", features = ["openssl"] } -brotli2 = "0.3.3" +brotli = "3.3.3" const-str = "0.3" env_logger = "0.9" flate2 = "1.0.13" diff --git a/awc/tests/utils.rs b/awc/tests/utils.rs index 9a3743d8b..2532640c6 100644 --- a/awc/tests/utils.rs +++ b/awc/tests/utils.rs @@ -41,16 +41,22 @@ pub mod deflate { pub mod brotli { 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 { - 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.finish().unwrap() + encoder.flush().unwrap(); + encoder.into_inner() } pub fn decode(bytes: impl AsRef<[u8]>) -> Vec { - let mut decoder = BrotliDecoder::new(bytes.as_ref()); + let mut decoder = BrotliDecoder::new(bytes.as_ref(), 8_096); let mut buf = Vec::new(); decoder.read_to_end(&mut buf).unwrap(); buf diff --git a/tests/utils.rs b/tests/utils.rs index 9a3743d8b..2532640c6 100644 --- a/tests/utils.rs +++ b/tests/utils.rs @@ -41,16 +41,22 @@ pub mod deflate { pub mod brotli { 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 { - 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.finish().unwrap() + encoder.flush().unwrap(); + encoder.into_inner() } pub fn decode(bytes: impl AsRef<[u8]>) -> Vec { - let mut decoder = BrotliDecoder::new(bytes.as_ref()); + let mut decoder = BrotliDecoder::new(bytes.as_ref(), 8_096); let mut buf = Vec::new(); decoder.read_to_end(&mut buf).unwrap(); buf