mirror of https://github.com/fafhrd91/actix-web
update brotli crate to 3.3.3
This commit is contained in:
parent
1505730684
commit
984238dc70
|
@ -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" }
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ where
|
|||
pub fn new(stream: S, encoding: ContentEncoding) -> Decoder<S> {
|
||||
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")]
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<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.finish().unwrap()
|
||||
encoder.flush().unwrap();
|
||||
encoder.into_inner()
|
||||
}
|
||||
|
||||
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();
|
||||
decoder.read_to_end(&mut buf).unwrap();
|
||||
buf
|
||||
|
|
|
@ -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<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.finish().unwrap()
|
||||
encoder.flush().unwrap();
|
||||
encoder.into_inner()
|
||||
}
|
||||
|
||||
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();
|
||||
decoder.read_to_end(&mut buf).unwrap();
|
||||
buf
|
||||
|
|
Loading…
Reference in New Issue