rename feature to dangerous-h2c

This commit is contained in:
Rob Ede 2021-11-22 16:34:28 +00:00
parent 6a461dbb23
commit 1b7a79719e
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 35 additions and 26 deletions

View File

@ -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"

View File

@ -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<Uri, Box<dyn ConnectionIo>> {
fn into_connection_io(self) -> (Box<dyn ConnectionIo>, 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<T, U> Service<Connection<T, U>> for NoOpTlsConnectorService
where
U: ActixStream + 'static,

View File

@ -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()