diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 866fcf3..8e610e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use log::{debug, error, info}; use std::{convert::Infallible, env, time::Duration}; -use http_types::Url; +use url::Url; use hyper::client::{HttpConnector,connect::dns::GaiResolver}; use hyper_rustls::HttpsConnector; use warp::{Filter, host::Authority}; @@ -212,7 +212,7 @@ async fn main() { tcp_listener.set_nonblocking(true).unwrap(); info!("Listening on {}", tcp_listener.local_addr().unwrap()); - let server: hyper::server::Server<_, _> = hyper::server::Server::from_tcp(tcp_listener) + let server = hyper::server::Server::from_tcp(tcp_listener) .unwrap() .tcp_keepalive(Some(Duration::from_secs(30 * 60))) .serve(hyper::service::make_service_fn(move |_| { @@ -220,8 +220,24 @@ async fn main() { async move { Ok::<_, Infallible>(service) } - })); - + })) + .with_graceful_shutdown(async move { + // Defer to C-c handler whenever we're not on Unix + // TODO consider using a diverging future here + #[cfg(not(unix))] + return tokio::signal::ctrl_c().await.unwrap(); + #[cfg(unix)] + { + use tokio::signal::unix::{signal, SignalKind}; + + signal(SignalKind::terminate()) + .unwrap() + .recv() + .await + .unwrap() + } + }); + if let Err(err) = server.await { error!("Error serving requests: {}", err); std::process::exit(1); |