diff --git a/src/app.rs b/src/app.rs index 76a3a1ce4..42ce62d89 100644 --- a/src/app.rs +++ b/src/app.rs @@ -31,6 +31,7 @@ where chain: T, extensions: Extensions, state: Vec>, + host: String, _t: PhantomData<(P,)>, } @@ -42,6 +43,7 @@ impl App { chain: AppChain, extensions: Extensions::new(), state: Vec::new(), + host: "localhost:8080".to_string(), _t: PhantomData, } } @@ -140,6 +142,7 @@ where default: None, factory_ref: fref, extensions: self.extensions, + host: self.host, _t: PhantomData, } } @@ -172,6 +175,7 @@ where chain, state: self.state, extensions: self.extensions, + host: self.host, _t: PhantomData, } } @@ -221,6 +225,7 @@ where factory_ref: fref, extensions: self.extensions, state: self.state, + host: self.host, services: vec![Box::new(ServiceFactoryWrapper::new(service))], _t: PhantomData, } @@ -233,8 +238,8 @@ where /// html#method.host) documentation for more information. /// /// By default host name is set to a "localhost" value. - pub fn hostname(self, _val: &str) -> Self { - // self.host = val.to_owned(); + pub fn hostname(mut self, val: &str) -> Self { + self.host = val.to_owned(); self } } @@ -249,6 +254,7 @@ pub struct AppRouter { factory_ref: Rc>>>, extensions: Extensions, state: Vec>, + host: String, _t: PhantomData<(P, B)>, } @@ -343,6 +349,7 @@ where default: self.default, factory_ref: self.factory_ref, extensions: self.extensions, + host: self.host, _t: PhantomData, } } diff --git a/src/server.rs b/src/server.rs index d95743651..5d717817d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -2,9 +2,7 @@ use std::marker::PhantomData; use std::sync::Arc; use std::{fmt, io, net}; -use actix_http::{ - body::MessageBody, HttpService, KeepAlive, Request, Response, ServiceConfig, -}; +use actix_http::{body::MessageBody, HttpService, KeepAlive, Request, Response}; use actix_rt::System; use actix_server::{Server, ServerBuilder}; use actix_server_config::ServerConfig; @@ -13,8 +11,8 @@ use parking_lot::Mutex; use net2::TcpBuilder; -#[cfg(feature = "tls")] -use native_tls::TlsAcceptor; +// #[cfg(feature = "tls")] +// use native_tls::TlsAcceptor; #[cfg(feature = "ssl")] use openssl::ssl::{SslAcceptor, SslAcceptorBuilder}; @@ -245,27 +243,28 @@ where lst, move || { let c = cfg.lock(); - let service_config = - ServiceConfig::new(c.keep_alive, c.client_timeout, 0); - HttpService::with_config(service_config, factory()) + HttpService::build() + .keep_alive(c.keep_alive) + .client_timeout(c.client_timeout) + .finish(factory()) }, )?); Ok(self) } - #[cfg(feature = "tls")] - /// Use listener for accepting incoming tls connection requests - /// - /// HttpServer does not change any configuration for TcpListener, - /// it needs to be configured before passing it to listen() method. - pub fn listen_tls(self, lst: net::TcpListener, acceptor: TlsAcceptor) -> Self { - use actix_net::service::NewServiceExt; + // #[cfg(feature = "tls")] + // /// Use listener for accepting incoming tls connection requests + // /// + // /// HttpServer does not change any configuration for TcpListener, + // /// it needs to be configured before passing it to listen() method. + // pub fn listen_nativetls(self, lst: net::TcpListener, acceptor: TlsAcceptor) -> Self { + // use actix_server::ssl; - self.listen_with(lst, move || { - ssl::NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ()) - }) - } + // self.listen_with(lst, move || { + // ssl::NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ()) + // }) + // } #[cfg(feature = "ssl")] /// Use listener for accepting incoming tls connection requests @@ -276,12 +275,16 @@ where lst: net::TcpListener, builder: SslAcceptorBuilder, ) -> io::Result { - self.listen_ssl_inner(lst, openssl_acceptor(builder)?); + self.listen_ssl_inner(lst, openssl_acceptor(builder)?)?; Ok(self) } #[cfg(feature = "ssl")] - fn listen_ssl_inner(&mut self, lst: net::TcpListener, acceptor: SslAcceptor) { + fn listen_ssl_inner( + &mut self, + lst: net::TcpListener, + acceptor: SslAcceptor, + ) -> io::Result<()> { use actix_server::ssl::{OpensslAcceptor, SslError}; let acceptor = OpensslAcceptor::new(acceptor); @@ -298,15 +301,18 @@ where lst, move || { let c = cfg.lock(); - let service_config = - ServiceConfig::new(c.keep_alive, c.client_timeout, c.client_timeout); acceptor.clone().map_err(|e| SslError::Ssl(e)).and_then( - HttpService::with_config(service_config, factory()) + HttpService::build() + .keep_alive(c.keep_alive) + .client_timeout(c.client_timeout) + .client_disconnect(c.client_shutdown) + .finish(factory()) .map_err(|e| SslError::Service(e)) .map_init_err(|_| ()), ) }, - )); + )?); + Ok(()) } #[cfg(feature = "rust-tls")] @@ -315,7 +321,6 @@ where /// This method sets alpn protocols to "h2" and "http/1.1" pub fn listen_rustls(self, lst: net::TcpListener, config: ServerConfig) -> Self { use super::{RustlsAcceptor, ServerFlags}; - use actix_net::service::NewServiceExt; self.listen_with(lst, move || { RustlsAcceptor::with_flags(config.clone(), flags).map_err(|_| ()) @@ -366,22 +371,21 @@ where } } - #[cfg(feature = "tls")] - /// The ssl socket address to bind - /// - /// To bind multiple addresses this method can be called multiple times. - pub fn bind_tls( - self, - addr: A, - acceptor: TlsAcceptor, - ) -> io::Result { - use actix_net::service::NewServiceExt; - use actix_net::ssl::NativeTlsAcceptor; + // #[cfg(feature = "tls")] + // /// The ssl socket address to bind + // /// + // /// To bind multiple addresses this method can be called multiple times. + // pub fn bind_nativetls( + // self, + // addr: A, + // acceptor: TlsAcceptor, + // ) -> io::Result { + // use actix_server::ssl::NativeTlsAcceptor; - self.bind_with(addr, move || { - NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ()) - }) - } + // self.bind_with(addr, move || { + // NativeTlsAcceptor::new(acceptor.clone()).map_err(|_| ()) + // }) + // } #[cfg(feature = "ssl")] /// Start listening for incoming tls connections. @@ -399,7 +403,7 @@ where let acceptor = openssl_acceptor(builder)?; for lst in sockets { - self.listen_ssl_inner(lst, acceptor.clone()); + self.listen_ssl_inner(lst, acceptor.clone())?; } Ok(self) @@ -415,14 +419,7 @@ where builder: ServerConfig, ) -> io::Result { use super::{RustlsAcceptor, ServerFlags}; - use actix_net::service::NewServiceExt; - - // alpn support - let flags = if self.no_http2 { - ServerFlags::HTTP1 - } else { - ServerFlags::HTTP1 | ServerFlags::HTTP2 - }; + use actix_service::NewServiceExt; self.bind_with(addr, move || { RustlsAcceptor::with_flags(builder.clone(), flags).map_err(|_| ())