|
|
|
@ -53,14 +53,21 @@ macro_rules! status {
@@ -53,14 +53,21 @@ macro_rules! status {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub async fn serve(args: Args) -> BoxResult<()> { |
|
|
|
|
match args.tls.as_ref() { |
|
|
|
|
Some(_) => serve_https(args).await, |
|
|
|
|
None => serve_http(args).await, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub async fn serve_https(args: Args) -> BoxResult<()> { |
|
|
|
|
let args = Arc::new(args); |
|
|
|
|
let socket_addr = args.address()?; |
|
|
|
|
let (certs, key) = args.tls.clone().unwrap(); |
|
|
|
|
let inner = Arc::new(InnerService::new(args.clone())); |
|
|
|
|
if let Some((certs, key)) = args.tls.as_ref() { |
|
|
|
|
let config = ServerConfig::builder() |
|
|
|
|
.with_safe_defaults() |
|
|
|
|
.with_no_client_auth() |
|
|
|
|
.with_single_cert(certs.clone(), key.clone())?; |
|
|
|
|
.with_single_cert(certs, key)?; |
|
|
|
|
let tls_acceptor = TlsAcceptor::from(Arc::new(config)); |
|
|
|
|
let arc_acceptor = Arc::new(tls_acceptor); |
|
|
|
|
let listener = TcpListener::bind(&socket_addr).await?; |
|
|
|
@ -84,8 +91,15 @@ pub async fn serve(args: Args) -> BoxResult<()> {
@@ -84,8 +91,15 @@ pub async fn serve(args: Args) -> BoxResult<()> {
|
|
|
|
|
} |
|
|
|
|
})); |
|
|
|
|
print_listening(args.address.as_str(), args.port, true); |
|
|
|
|
server.await?; |
|
|
|
|
} else { |
|
|
|
|
let graceful = server.with_graceful_shutdown(shutdown_signal()); |
|
|
|
|
graceful.await?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub async fn serve_http(args: Args) -> BoxResult<()> { |
|
|
|
|
let args = Arc::new(args); |
|
|
|
|
let socket_addr = args.address()?; |
|
|
|
|
let inner = Arc::new(InnerService::new(args.clone())); |
|
|
|
|
let server = hyper::Server::try_bind(&socket_addr)?.serve(make_service_fn(move |_| { |
|
|
|
|
let inner = inner.clone(); |
|
|
|
|
async move { |
|
|
|
@ -96,9 +110,8 @@ pub async fn serve(args: Args) -> BoxResult<()> {
@@ -96,9 +110,8 @@ pub async fn serve(args: Args) -> BoxResult<()> {
|
|
|
|
|
} |
|
|
|
|
})); |
|
|
|
|
print_listening(args.address.as_str(), args.port, false); |
|
|
|
|
server.await?; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let graceful = server.with_graceful_shutdown(shutdown_signal()); |
|
|
|
|
graceful.await?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -751,3 +764,9 @@ fn retrive_listening_addrs(address: &str) -> Vec<String> {
@@ -751,3 +764,9 @@ fn retrive_listening_addrs(address: &str) -> Vec<String> {
|
|
|
|
|
} |
|
|
|
|
vec![address.to_owned()] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async fn shutdown_signal() { |
|
|
|
|
tokio::signal::ctrl_c() |
|
|
|
|
.await |
|
|
|
|
.expect("Failed to install CTRL+C signal handler") |
|
|
|
|
} |
|
|
|
|