mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
Cleaned unnecessary Option<_> around ServerBuilder in server.rs/HttpServer (#863)
This commit is contained in:
parent
ded1e86e7e
commit
801cc2ed5d
@ -9,6 +9,10 @@
|
|||||||
* Add `test::TestRequest::set_json()` convenience method to automatically
|
* Add `test::TestRequest::set_json()` convenience method to automatically
|
||||||
serialize data and set header in test requests.
|
serialize data and set header in test requests.
|
||||||
|
|
||||||
|
### Changes
|
||||||
|
|
||||||
|
* Drop an unnecessary `Option<_>` indirection around `ServerBuilder` from `HttpServer`. #863
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
* Clear http requests pool on app service drop #860
|
* Clear http requests pool on app service drop #860
|
||||||
|
@ -64,7 +64,7 @@ where
|
|||||||
config: Arc<Mutex<Config>>,
|
config: Arc<Mutex<Config>>,
|
||||||
backlog: i32,
|
backlog: i32,
|
||||||
sockets: Vec<Socket>,
|
sockets: Vec<Socket>,
|
||||||
builder: Option<ServerBuilder>,
|
builder: ServerBuilder,
|
||||||
_t: PhantomData<(S, B)>,
|
_t: PhantomData<(S, B)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ where
|
|||||||
})),
|
})),
|
||||||
backlog: 1024,
|
backlog: 1024,
|
||||||
sockets: Vec::new(),
|
sockets: Vec::new(),
|
||||||
builder: Some(ServerBuilder::default()),
|
builder: ServerBuilder::default(),
|
||||||
_t: PhantomData,
|
_t: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ where
|
|||||||
/// By default http server uses number of available logical cpu as threads
|
/// By default http server uses number of available logical cpu as threads
|
||||||
/// count.
|
/// count.
|
||||||
pub fn workers(mut self, num: usize) -> Self {
|
pub fn workers(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().workers(num));
|
self.builder = self.builder.workers(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ where
|
|||||||
/// This method should be called before `bind()` method call.
|
/// This method should be called before `bind()` method call.
|
||||||
pub fn backlog(mut self, backlog: i32) -> Self {
|
pub fn backlog(mut self, backlog: i32) -> Self {
|
||||||
self.backlog = backlog;
|
self.backlog = backlog;
|
||||||
self.builder = Some(self.builder.take().unwrap().backlog(backlog));
|
self.builder = self.builder.backlog(backlog);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default max connections is set to a 25k.
|
/// By default max connections is set to a 25k.
|
||||||
pub fn maxconn(mut self, num: usize) -> Self {
|
pub fn maxconn(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().maxconn(num));
|
self.builder = self.builder.maxconn(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default max connections is set to a 256.
|
/// By default max connections is set to a 256.
|
||||||
pub fn maxconnrate(mut self, num: usize) -> Self {
|
pub fn maxconnrate(mut self, num: usize) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().maxconnrate(num));
|
self.builder = self.builder.maxconnrate(num);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,13 +190,13 @@ where
|
|||||||
|
|
||||||
/// Stop actix system.
|
/// Stop actix system.
|
||||||
pub fn system_exit(mut self) -> Self {
|
pub fn system_exit(mut self) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().system_exit());
|
self.builder = self.builder.system_exit();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Disable signal handling
|
/// Disable signal handling
|
||||||
pub fn disable_signals(mut self) -> Self {
|
pub fn disable_signals(mut self) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().disable_signals());
|
self.builder = self.builder.disable_signals();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ where
|
|||||||
///
|
///
|
||||||
/// By default shutdown timeout sets to 30 seconds.
|
/// By default shutdown timeout sets to 30 seconds.
|
||||||
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
pub fn shutdown_timeout(mut self, sec: u64) -> Self {
|
||||||
self.builder = Some(self.builder.take().unwrap().shutdown_timeout(sec));
|
self.builder = self.builder.shutdown_timeout(sec);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ where
|
|||||||
scheme: "http",
|
scheme: "http",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -250,8 +250,7 @@ where
|
|||||||
.client_timeout(c.client_timeout)
|
.client_timeout(c.client_timeout)
|
||||||
.finish(factory())
|
.finish(factory())
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,20 +259,19 @@ where
|
|||||||
///
|
///
|
||||||
/// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
pub fn listen_ssl(
|
pub fn listen_ssl(
|
||||||
mut self,
|
self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
builder: SslAcceptorBuilder,
|
builder: SslAcceptorBuilder,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
self.listen_ssl_inner(lst, openssl_acceptor(builder)?)?;
|
self.listen_ssl_inner(lst, openssl_acceptor(builder)?)
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "ssl")]
|
#[cfg(feature = "ssl")]
|
||||||
fn listen_ssl_inner(
|
fn listen_ssl_inner(
|
||||||
&mut self,
|
mut self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
acceptor: SslAcceptor,
|
acceptor: SslAcceptor,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<Self> {
|
||||||
use actix_server::ssl::{OpensslAcceptor, SslError};
|
use actix_server::ssl::{OpensslAcceptor, SslError};
|
||||||
|
|
||||||
let acceptor = OpensslAcceptor::new(acceptor);
|
let acceptor = OpensslAcceptor::new(acceptor);
|
||||||
@ -285,7 +283,7 @@ where
|
|||||||
scheme: "https",
|
scheme: "https",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -300,8 +298,8 @@ where
|
|||||||
.map_init_err(|_| ()),
|
.map_init_err(|_| ()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
Ok(())
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
@ -309,20 +307,19 @@ where
|
|||||||
///
|
///
|
||||||
/// This method sets alpn protocols to "h2" and "http/1.1"
|
/// This method sets alpn protocols to "h2" and "http/1.1"
|
||||||
pub fn listen_rustls(
|
pub fn listen_rustls(
|
||||||
mut self,
|
self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
config: RustlsServerConfig,
|
config: RustlsServerConfig,
|
||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
self.listen_rustls_inner(lst, config)?;
|
self.listen_rustls_inner(lst, config)
|
||||||
Ok(self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rust-tls")]
|
#[cfg(feature = "rust-tls")]
|
||||||
fn listen_rustls_inner(
|
fn listen_rustls_inner(
|
||||||
&mut self,
|
mut self,
|
||||||
lst: net::TcpListener,
|
lst: net::TcpListener,
|
||||||
mut config: RustlsServerConfig,
|
mut config: RustlsServerConfig,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<Self> {
|
||||||
use actix_server::ssl::{RustlsAcceptor, SslError};
|
use actix_server::ssl::{RustlsAcceptor, SslError};
|
||||||
|
|
||||||
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
|
let protos = vec!["h2".to_string().into(), "http/1.1".to_string().into()];
|
||||||
@ -337,7 +334,7 @@ where
|
|||||||
scheme: "https",
|
scheme: "https",
|
||||||
});
|
});
|
||||||
|
|
||||||
self.builder = Some(self.builder.take().unwrap().listen(
|
self.builder = self.builder.listen(
|
||||||
format!("actix-web-service-{}", addr),
|
format!("actix-web-service-{}", addr),
|
||||||
lst,
|
lst,
|
||||||
move || {
|
move || {
|
||||||
@ -352,8 +349,8 @@ where
|
|||||||
.map_init_err(|_| ()),
|
.map_init_err(|_| ()),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
)?);
|
)?;
|
||||||
Ok(())
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The socket address to bind
|
/// The socket address to bind
|
||||||
@ -416,7 +413,7 @@ where
|
|||||||
let acceptor = openssl_acceptor(builder)?;
|
let acceptor = openssl_acceptor(builder)?;
|
||||||
|
|
||||||
for lst in sockets {
|
for lst in sockets {
|
||||||
self.listen_ssl_inner(lst, acceptor.clone())?;
|
self = self.listen_ssl_inner(lst, acceptor.clone())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
@ -433,7 +430,7 @@ where
|
|||||||
) -> io::Result<Self> {
|
) -> io::Result<Self> {
|
||||||
let sockets = self.bind2(addr)?;
|
let sockets = self.bind2(addr)?;
|
||||||
for lst in sockets {
|
for lst in sockets {
|
||||||
self.listen_rustls_inner(lst, config.clone())?;
|
self = self.listen_rustls_inner(lst, config.clone())?;
|
||||||
}
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
@ -473,8 +470,8 @@ where
|
|||||||
/// sys.run() // <- Run actix system, this method starts all async processes
|
/// sys.run() // <- Run actix system, this method starts all async processes
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn start(mut self) -> Server {
|
pub fn start(self) -> Server {
|
||||||
self.builder.take().unwrap().start()
|
self.builder.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Spawn new thread and start listening for incoming connections.
|
/// Spawn new thread and start listening for incoming connections.
|
||||||
|
Loading…
Reference in New Issue
Block a user