diff --git a/Cargo.toml b/Cargo.toml index 3e62e9315..190b645d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -52,10 +52,10 @@ cookies = ["actix-http/cookies"] secure-cookies = ["actix-http/secure-cookies"] # openssl -openssl = ["actix-tls/accept", "actix-tls/openssl"] +openssl = ["actix-http/openssl", "actix-tls/accept", "actix-tls/openssl"] # rustls -rustls = ["actix-tls/accept", "actix-tls/rustls"] +rustls = ["actix-http/rustls", "actix-tls/accept", "actix-tls/rustls"] [[example]] name = "basic" @@ -108,7 +108,7 @@ time = { version = "0.2.23", default-features = false, features = ["std"] } url = "2.1" [dev-dependencies] -actix-test = "0.0.1" +actix-test = { version = "0.0.1", features = ["openssl", "rustls"] } awc = { version = "3.0.0-beta.3", features = ["openssl"] } brotli2 = "0.3.2" diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index d9af75aa5..4857f083d 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -48,7 +48,7 @@ actix-service = "2.0.0-beta.4" actix-codec = "0.4.0-beta.1" actix-utils = "3.0.0-beta.4" actix-rt = "2.2" -actix-tls = "3.0.0-beta.5" +actix-tls = { version = "3.0.0-beta.5", features = ["accept", "connect"] } ahash = "0.7" base64 = "0.13" diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index 90608b933..67a3ec42e 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -153,11 +153,14 @@ where S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, + B: MessageBody + 'static, + X: ServiceFactory, X::Future: 'static, X::Error: Into, X::InitError: fmt::Debug, + U: ServiceFactory< (Request, Framed), Config = (), @@ -187,11 +190,12 @@ where #[cfg(feature = "openssl")] mod openssl { - use super::*; use actix_service::ServiceFactoryExt; use actix_tls::accept::openssl::{Acceptor, SslAcceptor, SslError, TlsStream}; use actix_tls::accept::TlsError; + use super::*; + impl HttpService, S, B, X, U> where S: ServiceFactory, @@ -200,11 +204,14 @@ mod openssl { S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, + B: MessageBody + 'static, + X: ServiceFactory, X::Future: 'static, X::Error: Into, X::InitError: fmt::Debug, + U: ServiceFactory< (Request, Framed, h1::Codec>), Config = (), @@ -252,11 +259,11 @@ mod openssl { mod rustls { use std::io; - use actix_service::ServiceFactoryExt as _; use actix_tls::accept::rustls::{Acceptor, ServerConfig, Session, TlsStream}; use actix_tls::accept::TlsError; use super::*; + use actix_service::ServiceFactoryExt; impl HttpService, S, B, X, U> where @@ -266,11 +273,14 @@ mod rustls { S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, + B: MessageBody + 'static, + X: ServiceFactory, X::Future: 'static, X::Error: Into, X::InitError: fmt::Debug, + U: ServiceFactory< (Request, Framed, h1::Codec>), Config = (), @@ -280,7 +290,7 @@ mod rustls { U::Error: fmt::Display + Into, U::InitError: fmt::Debug, { - /// Create openssl based service + /// Create rustls based service pub fn rustls( self, mut config: ServerConfig, @@ -321,17 +331,21 @@ impl ServiceFactory<(T, Protocol, Option)> for HttpService where T: AsyncRead + AsyncWrite + Unpin + 'static, + S: ServiceFactory, S::Future: 'static, S::Error: Into + 'static, S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, + B: MessageBody + 'static, + X: ServiceFactory, X::Future: 'static, X::Error: Into, X::InitError: fmt::Debug, + U: ServiceFactory<(Request, Framed), Config = (), Response = ()>, U::Future: 'static, U::Error: fmt::Display + Into, diff --git a/actix-test/src/lib.rs b/actix-test/src/lib.rs index 9b5e23e5e..bd86c27ad 100644 --- a/actix-test/src/lib.rs +++ b/actix-test/src/lib.rs @@ -35,7 +35,10 @@ use std::{fmt, net, sync::mpsc, thread, time}; use actix_codec::{AsyncRead, AsyncWrite, Framed}; pub use actix_http::test::TestBuffer; -use actix_http::{http::Method, ws, HttpService, Request}; +use actix_http::{ + http::{HeaderMap, Method}, + ws, HttpService, Request, +}; use actix_service::{map_config, IntoServiceFactory, ServiceFactory}; use actix_web::{ dev::{AppConfig, MessageBody, Server, Service}, @@ -446,6 +449,14 @@ impl TestServer { self.ws_at("/").await } + /// Get default HeaderMap of Client. + /// + /// Returns Some(&mut HeaderMap) when Client object is unique + /// (No other clone of client exists at the same time). + pub fn client_headers(&mut self) -> Option<&mut HeaderMap> { + self.client.headers() + } + /// Gracefully stop HTTP server. pub async fn stop(self) { self.server.stop(true).await; diff --git a/actix-web-actors/tests/test_ws.rs b/actix-web-actors/tests/test_ws.rs index f4c91aeec..0a8e50b3e 100644 --- a/actix-web-actors/tests/test_ws.rs +++ b/actix-web-actors/tests/test_ws.rs @@ -1,7 +1,7 @@ use actix::prelude::*; use actix_web::{ http::{header, StatusCode}, - test, web, App, HttpRequest, HttpResponse, + web, App, HttpRequest, HttpResponse, }; use actix_web_actors::*; use bytes::Bytes; @@ -62,7 +62,7 @@ async fn test_simple() { #[actix_rt::test] async fn test_with_credentials() { - let mut srv = test::start(|| { + let mut srv = actix_test::start(|| { App::new().service(web::resource("/").to( |req: HttpRequest, stream: web::Payload| async move { if req.headers().contains_key("Authorization") { diff --git a/codecov.yml b/codecov.yml index 27f21e987..d80835c7f 100644 --- a/codecov.yml +++ b/codecov.yml @@ -13,4 +13,3 @@ ignore: # ignore code coverage on following paths - "**/tests" - "**/benches" - "**/examples" - - "test-server" diff --git a/src/data.rs b/src/data.rs index 710d65e77..bd9b88301 100644 --- a/src/data.rs +++ b/src/data.rs @@ -148,20 +148,13 @@ impl DataFactory for Data { #[cfg(test)] mod tests { - use std::sync::atomic::{AtomicUsize, Ordering}; - - use actix_service::Service; - use super::*; - use crate::dev::Service; - use crate::http::StatusCode; - use crate::test::{self, init_service, TestRequest}; use crate::{ + dev::Service, http::StatusCode, test::{init_service, TestRequest}, web, App, HttpResponse, }; - use crate::{web, App, HttpResponse}; #[actix_rt::test] async fn test_data_extractor() { diff --git a/src/server.rs b/src/server.rs index 56cb27acf..fda5e1deb 100644 --- a/src/server.rs +++ b/src/server.rs @@ -71,12 +71,15 @@ impl HttpServer where F: Fn() -> I + Send + Clone + 'static, I: IntoServiceFactory, + S: ServiceFactory + 'static, + // S::Future: 'static, S::Error: Into + 'static, S::InitError: fmt::Debug, S::Response: Into> + 'static, >::Future: 'static, S::Service: 'static, + // S::Service: 'static, B: MessageBody + 'static, { /// Create new HTTP server with application factory @@ -294,7 +297,7 @@ where })?; Ok(self) } - + #[cfg(feature = "openssl")] /// Use listener for accepting incoming tls connection requests /// @@ -347,9 +350,10 @@ where })) .openssl(acceptor.clone()) })?; + Ok(self) } - + #[cfg(feature = "rustls")] /// Use listener for accepting incoming tls connection requests ///