mirror of https://github.com/fafhrd91/actix-web
rename feature to dangerous-h2c
This commit is contained in:
parent
6a461dbb23
commit
1b7a79719e
|
@ -55,7 +55,7 @@ __compress = []
|
||||||
# Enable dangerous feature for testing and local network usage:
|
# Enable dangerous feature for testing and local network usage:
|
||||||
# - HTTP/2 over TCP(No Tls).
|
# - HTTP/2 over TCP(No Tls).
|
||||||
# DO NOT enable this over any internet use case.
|
# DO NOT enable this over any internet use case.
|
||||||
dangerous = []
|
dangerous-h2c = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.4.1"
|
actix-codec = "0.4.1"
|
||||||
|
|
|
@ -280,18 +280,18 @@ where
|
||||||
|
|
||||||
let tls_service = match self.ssl {
|
let tls_service = match self.ssl {
|
||||||
SslConnector::None => {
|
SslConnector::None => {
|
||||||
#[cfg(not(feature = "dangerous"))]
|
#[cfg(not(feature = "dangerous-h2c"))]
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
#[cfg(feature = "dangerous")]
|
#[cfg(feature = "dangerous-h2c")]
|
||||||
{
|
{
|
||||||
/*
|
use std::{
|
||||||
With dangerous feature enabled Connector would use a NoOp Tls connection service that
|
future::{ready, Ready},
|
||||||
pass through plain TCP as Tls connection.
|
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>> {
|
impl IntoConnectionIo for TcpConnection<Uri, Box<dyn ConnectionIo>> {
|
||||||
fn into_connection_io(self) -> (Box<dyn ConnectionIo>, Protocol) {
|
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)]
|
#[derive(Clone)]
|
||||||
struct NoOpTlsConnectorService;
|
struct NoOpTlsConnectorService;
|
||||||
|
|
||||||
use actix_tls::connect::Connection;
|
|
||||||
use std::{
|
|
||||||
future::{ready, Ready},
|
|
||||||
io,
|
|
||||||
};
|
|
||||||
|
|
||||||
impl<T, U> Service<Connection<T, U>> for NoOpTlsConnectorService
|
impl<T, U> Service<Connection<T, U>> for NoOpTlsConnectorService
|
||||||
where
|
where
|
||||||
U: ActixStream + 'static,
|
U: ActixStream + 'static,
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
use std::collections::HashMap;
|
use std::{
|
||||||
use std::io::{Read, Write};
|
collections::HashMap,
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
io::{Read, Write},
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
net::{IpAddr, Ipv4Addr},
|
||||||
use std::sync::Arc;
|
sync::{
|
||||||
use std::time::Duration;
|
atomic::{AtomicUsize, Ordering},
|
||||||
|
Arc,
|
||||||
|
},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use actix_utils::future::ok;
|
use actix_utils::future::ok;
|
||||||
use brotli2::write::BrotliEncoder;
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use cookie::Cookie;
|
use cookie::Cookie;
|
||||||
use flate2::read::GzDecoder;
|
|
||||||
use flate2::write::GzEncoder;
|
|
||||||
use flate2::Compression;
|
|
||||||
use futures_util::stream;
|
use futures_util::stream;
|
||||||
use rand::Rng;
|
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::{
|
use actix_http::{
|
||||||
http::{self, StatusCode},
|
http::{self, StatusCode},
|
||||||
HttpService,
|
HttpService,
|
||||||
|
@ -24,7 +30,6 @@ use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||||
use actix_web::{
|
use actix_web::{
|
||||||
dev::{AppConfig, BodyEncoding},
|
dev::{AppConfig, BodyEncoding},
|
||||||
http::header,
|
http::header,
|
||||||
middleware::Compress,
|
|
||||||
web, App, Error, HttpRequest, HttpResponse,
|
web, App, Error, HttpRequest, HttpResponse,
|
||||||
};
|
};
|
||||||
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
use awc::error::{JsonPayloadError, PayloadError, SendRequestError};
|
||||||
|
@ -463,11 +468,12 @@ async fn test_with_query_parameter() {
|
||||||
assert!(res.status().is_success());
|
assert!(res.status().is_success());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-gzip")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_no_decompress() {
|
async fn test_no_decompress() {
|
||||||
let srv = actix_test::start(|| {
|
let srv = actix_test::start(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(Compress::default())
|
.wrap(actix_web::middleware::Compress::default())
|
||||||
.service(web::resource("/").route(web::to(|| {
|
.service(web::resource("/").route(web::to(|| {
|
||||||
let mut res = HttpResponse::Ok().body(STR);
|
let mut res = HttpResponse::Ok().body(STR);
|
||||||
res.encoding(header::ContentEncoding::Gzip);
|
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()));
|
assert_eq!(Bytes::from(dec), Bytes::from_static(STR.as_ref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-gzip")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_client_gzip_encoding() {
|
async fn test_client_gzip_encoding() {
|
||||||
let srv = actix_test::start(|| {
|
let srv = actix_test::start(|| {
|
||||||
|
@ -530,6 +537,7 @@ async fn test_client_gzip_encoding() {
|
||||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-gzip")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_client_gzip_encoding_large() {
|
async fn test_client_gzip_encoding_large() {
|
||||||
let srv = actix_test::start(|| {
|
let srv = actix_test::start(|| {
|
||||||
|
@ -553,6 +561,7 @@ async fn test_client_gzip_encoding_large() {
|
||||||
assert_eq!(bytes, Bytes::from(STR.repeat(10)));
|
assert_eq!(bytes, Bytes::from(STR.repeat(10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-gzip")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_client_gzip_encoding_large_random() {
|
async fn test_client_gzip_encoding_large_random() {
|
||||||
let data = rand::thread_rng()
|
let data = rand::thread_rng()
|
||||||
|
@ -581,6 +590,7 @@ async fn test_client_gzip_encoding_large_random() {
|
||||||
assert_eq!(bytes, Bytes::from(data));
|
assert_eq!(bytes, Bytes::from(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-brotli")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_client_brotli_encoding() {
|
async fn test_client_brotli_encoding() {
|
||||||
let srv = actix_test::start(|| {
|
let srv = actix_test::start(|| {
|
||||||
|
@ -603,6 +613,7 @@ async fn test_client_brotli_encoding() {
|
||||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "compress-brotli")]
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_client_brotli_encoding_large_random() {
|
async fn test_client_brotli_encoding_large_random() {
|
||||||
let data = rand::thread_rng()
|
let data = rand::thread_rng()
|
||||||
|
|
Loading…
Reference in New Issue