From 1b7a79719ec7a00fdf198d480957e2e8138e88fd Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 22 Nov 2021 16:34:28 +0000 Subject: [PATCH] rename feature to dangerous-h2c --- awc/Cargo.toml | 2 +- awc/src/client/connector.rs | 24 +++++++++++------------- awc/tests/test_client.rs | 35 +++++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/awc/Cargo.toml b/awc/Cargo.toml index f26696514..1dbb0ec19 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -55,7 +55,7 @@ __compress = [] # Enable dangerous feature for testing and local network usage: # - HTTP/2 over TCP(No Tls). # DO NOT enable this over any internet use case. -dangerous = [] +dangerous-h2c = [] [dependencies] actix-codec = "0.4.1" diff --git a/awc/src/client/connector.rs b/awc/src/client/connector.rs index f5d313ea7..3fe4e06b7 100644 --- a/awc/src/client/connector.rs +++ b/awc/src/client/connector.rs @@ -280,18 +280,18 @@ where let tls_service = match self.ssl { SslConnector::None => { - #[cfg(not(feature = "dangerous"))] + #[cfg(not(feature = "dangerous-h2c"))] { None } - #[cfg(feature = "dangerous")] + #[cfg(feature = "dangerous-h2c")] { - /* - With dangerous feature enabled Connector would use a NoOp Tls connection service that - pass through plain TCP as Tls connection. + use std::{ + future::{ready, Ready}, + io, + }; - The Protocol version of this fake Tls connection is set to be HTTP2. - */ + use actix_tls::connect::Connection; impl IntoConnectionIo for TcpConnection> { fn into_connection_io(self) -> (Box, Protocol) { @@ -300,15 +300,13 @@ where } } + /// With the `dangerous-h2c` feature enabled, this connector uses a no-op TLS + /// connection service that passes through plain TCP as a TLS connection. + /// + /// The protocol version of this fake TLS connection is set to be HTTP/2. #[derive(Clone)] struct NoOpTlsConnectorService; - use actix_tls::connect::Connection; - use std::{ - future::{ready, Ready}, - io, - }; - impl Service> for NoOpTlsConnectorService where U: ActixStream + 'static, diff --git a/awc/tests/test_client.rs b/awc/tests/test_client.rs index a0af0cab6..856a4ace2 100644 --- a/awc/tests/test_client.rs +++ b/awc/tests/test_client.rs @@ -1,20 +1,26 @@ -use std::collections::HashMap; -use std::io::{Read, Write}; -use std::net::{IpAddr, Ipv4Addr}; -use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; -use std::time::Duration; +use std::{ + collections::HashMap, + io::{Read, Write}, + net::{IpAddr, Ipv4Addr}, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, + time::Duration, +}; use actix_utils::future::ok; -use brotli2::write::BrotliEncoder; use bytes::Bytes; use cookie::Cookie; -use flate2::read::GzDecoder; -use flate2::write::GzEncoder; -use flate2::Compression; use futures_util::stream; use rand::Rng; +#[cfg(feature = "compress-brotli")] +use brotli2::write::BrotliEncoder; + +#[cfg(feature = "compress-gzip")] +use flate2::{read::GzDecoder, write::GzEncoder, Compression}; + use actix_http::{ http::{self, StatusCode}, HttpService, @@ -24,7 +30,6 @@ use actix_service::{fn_service, map_config, ServiceFactoryExt as _}; use actix_web::{ dev::{AppConfig, BodyEncoding}, http::header, - middleware::Compress, web, App, Error, HttpRequest, HttpResponse, }; use awc::error::{JsonPayloadError, PayloadError, SendRequestError}; @@ -463,11 +468,12 @@ async fn test_with_query_parameter() { assert!(res.status().is_success()); } +#[cfg(feature = "compress-gzip")] #[actix_rt::test] async fn test_no_decompress() { let srv = actix_test::start(|| { App::new() - .wrap(Compress::default()) + .wrap(actix_web::middleware::Compress::default()) .service(web::resource("/").route(web::to(|| { let mut res = HttpResponse::Ok().body(STR); res.encoding(header::ContentEncoding::Gzip); @@ -507,6 +513,7 @@ async fn test_no_decompress() { assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref())); } +#[cfg(feature = "compress-gzip")] #[actix_rt::test] async fn test_client_gzip_encoding() { let srv = actix_test::start(|| { @@ -530,6 +537,7 @@ async fn test_client_gzip_encoding() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(feature = "compress-gzip")] #[actix_rt::test] async fn test_client_gzip_encoding_large() { let srv = actix_test::start(|| { @@ -553,6 +561,7 @@ async fn test_client_gzip_encoding_large() { assert_eq!(bytes, Bytes::from(STR.repeat(10))); } +#[cfg(feature = "compress-gzip")] #[actix_rt::test] async fn test_client_gzip_encoding_large_random() { let data = rand::thread_rng() @@ -581,6 +590,7 @@ async fn test_client_gzip_encoding_large_random() { assert_eq!(bytes, Bytes::from(data)); } +#[cfg(feature = "compress-brotli")] #[actix_rt::test] async fn test_client_brotli_encoding() { let srv = actix_test::start(|| { @@ -603,6 +613,7 @@ async fn test_client_brotli_encoding() { assert_eq!(bytes, Bytes::from_static(STR.as_ref())); } +#[cfg(feature = "compress-brotli")] #[actix_rt::test] async fn test_client_brotli_encoding_large_random() { let data = rand::thread_rng()