aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.rs2
-rw-r--r--src/config.rs11
-rw-r--r--src/main.rs8
3 files changed, 21 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs
index c2b2bf2..cea5658 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -135,10 +135,12 @@ pub struct CliArgs {
pub print_completions: Option<structopt::clap::Shell>,
/// TLS certificate to use
+ #[cfg(feature = "tls")]
#[structopt(long = "tls-cert", requires = "tls-key")]
pub tls_cert: Option<PathBuf>,
/// TLS private key to use
+ #[cfg(feature = "tls")]
#[structopt(long = "tls-key", requires = "tls-cert")]
pub tls_key: Option<PathBuf>,
}
diff --git a/src/config.rs b/src/config.rs
index 6eeafef..e2b4c3a 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -7,6 +7,8 @@ use std::{
use anyhow::{anyhow, Context, Result};
use http::HeaderMap;
+
+#[cfg(feature = "tls")]
use rustls::internal::pemfile::{certs, pkcs8_private_keys};
use crate::{args::CliArgs, auth::RequiredAuth};
@@ -95,7 +97,11 @@ pub struct MiniserveConfig {
pub hide_version_footer: bool,
/// If set, use provided rustls config for TLS
+ #[cfg(feature = "tls")]
pub tls_rustls_config: Option<rustls::ServerConfig>,
+
+ #[cfg(not(feature = "tls"))]
+ pub tls_rustls_config: Option<()>,
}
impl MiniserveConfig {
@@ -131,6 +137,7 @@ impl MiniserveConfig {
_ => args.port,
};
+ #[cfg(feature = "tls")]
let tls_rustls_server_config = if let (Some(tls_cert), Some(tls_key)) =
(args.tls_cert, args.tls_key)
{
@@ -150,6 +157,10 @@ impl MiniserveConfig {
} else {
None
};
+
+ #[cfg(not(feature = "tls"))]
+ let tls_rustls_server_config = None;
+
Ok(MiniserveConfig {
verbose: args.verbose,
path: args.path.unwrap_or_else(|| PathBuf::from(".")),
diff --git a/src/main.rs b/src/main.rs
index 1432a1a..c60e153 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -227,6 +227,7 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.default_service(web::get().to(error_404))
});
+ #[cfg(feature = "tls")]
let srv = if let Some(tls_config) = miniserve_config.tls_rustls_config {
srv.bind_rustls(socket_addresses.as_slice(), tls_config)
.map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
@@ -239,6 +240,13 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.run()
};
+ #[cfg(not(feature = "tls"))]
+ let srv = srv
+ .bind(socket_addresses.as_slice())
+ .map_err(|e| ContextualError::IoError("Failed to bind server".to_string(), e))?
+ .shutdown_timeout(0)
+ .run();
+
println!(
"Serving path {path} at {addresses}",
path = Color::Yellow.paint(path_string).bold(),