mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
Switch brotli compressor to rust. (#1197)
* Switch to a rustified version of brotli. * Some memory optimizations. * Make brotli not optional anymore.
This commit is contained in:
@ -21,10 +21,10 @@ name = "awc"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
features = ["openssl", "rustls", "brotli", "flate2-zlib"]
|
||||
features = ["openssl", "rustls", "flate2-zlib"]
|
||||
|
||||
[features]
|
||||
default = ["brotli", "flate2-zlib"]
|
||||
default = ["flate2-zlib"]
|
||||
|
||||
# openssl
|
||||
openssl = ["open-ssl", "actix-http/openssl"]
|
||||
@ -32,9 +32,6 @@ openssl = ["open-ssl", "actix-http/openssl"]
|
||||
# rustls
|
||||
rustls = ["rust-tls", "actix-http/rustls"]
|
||||
|
||||
# brotli encoding, requires c compiler
|
||||
brotli = ["actix-http/brotli"]
|
||||
|
||||
# miniz-sys backend for flate2 crate
|
||||
flate2-zlib = ["actix-http/flate2-zlib"]
|
||||
|
||||
@ -69,7 +66,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" }
|
||||
brotli = "3.3.0"
|
||||
flate2 = { version="1.0.2" }
|
||||
env_logger = "0.6"
|
||||
webpki = { version = "0.21" }
|
||||
|
@ -23,13 +23,10 @@ use crate::frozen::FrozenClientRequest;
|
||||
use crate::sender::{PrepForSendingError, RequestSender, SendClientRequest};
|
||||
use crate::ClientConfig;
|
||||
|
||||
#[cfg(any(feature = "brotli", feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
const HTTPS_ENCODING: &str = "br, gzip, deflate";
|
||||
#[cfg(all(
|
||||
any(feature = "flate2-zlib", feature = "flate2-rust"),
|
||||
not(feature = "brotli")
|
||||
))]
|
||||
const HTTPS_ENCODING: &str = "gzip, deflate";
|
||||
#[cfg(not(any(feature = "flate2-zlib", feature = "flate2-rust")))]
|
||||
const HTTPS_ENCODING: &str = "br";
|
||||
|
||||
/// An HTTP Client request builder
|
||||
///
|
||||
@ -544,31 +541,23 @@ impl ClientRequest {
|
||||
|
||||
let mut slf = self;
|
||||
|
||||
// enable br only for https
|
||||
#[cfg(any(
|
||||
feature = "brotli",
|
||||
feature = "flate2-zlib",
|
||||
feature = "flate2-rust"
|
||||
))]
|
||||
{
|
||||
if slf.response_decompress {
|
||||
let https = slf
|
||||
.head
|
||||
.uri
|
||||
.scheme()
|
||||
.map(|s| s == &uri::Scheme::HTTPS)
|
||||
.unwrap_or(true);
|
||||
if slf.response_decompress {
|
||||
let https = slf
|
||||
.head
|
||||
.uri
|
||||
.scheme()
|
||||
.map(|s| s == &uri::Scheme::HTTPS)
|
||||
.unwrap_or(true);
|
||||
|
||||
if https {
|
||||
slf = slf.set_header_if_none(header::ACCEPT_ENCODING, HTTPS_ENCODING)
|
||||
} else {
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
{
|
||||
slf = slf
|
||||
.set_header_if_none(header::ACCEPT_ENCODING, "gzip, deflate")
|
||||
}
|
||||
};
|
||||
}
|
||||
if https {
|
||||
slf = slf.set_header_if_none(header::ACCEPT_ENCODING, HTTPS_ENCODING)
|
||||
} else {
|
||||
#[cfg(any(feature = "flate2-zlib", feature = "flate2-rust"))]
|
||||
{
|
||||
slf =
|
||||
slf.set_header_if_none(header::ACCEPT_ENCODING, "gzip, deflate")
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Ok(slf)
|
||||
|
@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use brotli2::write::BrotliEncoder;
|
||||
use brotli::write::BrotliEncoder;
|
||||
use bytes::Bytes;
|
||||
use flate2::read::GzDecoder;
|
||||
use flate2::write::GzEncoder;
|
||||
@ -568,7 +568,6 @@ async fn test_client_brotli_encoding() {
|
||||
// assert_eq!(bytes, Bytes::from(data));
|
||||
// }
|
||||
|
||||
// #[cfg(feature = "brotli")]
|
||||
// #[actix_rt::test]
|
||||
// async fn test_client_deflate_encoding() {
|
||||
// let srv = test::TestServer::start(|app| {
|
||||
|
Reference in New Issue
Block a user