Skip to content

Commit 160a812

Browse files
committed
Make TLS support optional
1 parent 47be257 commit 160a812

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ flate2 = "1.0.11"
1919
filetime = "0.2.7"
2020
pretty-bytes = "0.2.2"
2121
url = "2.1.0"
22-
hyper-native-tls = "0.3.0"
22+
hyper-native-tls = {version = "0.3.0", optional=true}
2323
mime_guess = "2.0"
2424
# Iron crates
2525
iron = "0.6.1"
@@ -28,3 +28,7 @@ multipart = { version = "0.16.1", features = ["iron"] }
2828
htmlescape = "0.3.1"
2929
percent-encoding = "2.1.0"
3030
path-dedot = "1"
31+
32+
[features]
33+
default = ["tls"]
34+
tls = ["hyper-native-tls"]

src/main.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,28 @@ fn main() {
328328
}
329329
let mut server = Iron::new(chain);
330330
server.threads = threads as usize;
331+
332+
#[cfg(feature = "tls")]
331333
let rv = if let Some(cert) = cert {
332334
use hyper_native_tls::NativeTlsServer;
333335
let ssl = NativeTlsServer::new(cert, certpass.unwrap_or("")).unwrap();
334336
server.https(&addr, ssl)
335337
} else {
336338
server.http(&addr)
337339
};
340+
#[cfg(not(feature = "tls"))]
341+
let rv = if cert.is_some() {
342+
printer
343+
.println_err(
344+
"{}: TLS support is not enabled during compilation of simple-http-server",
345+
&[("ERROR", &Some(build_spec(Some(Color::Red), true)))],
346+
)
347+
.unwrap();
348+
std::process::exit(1)
349+
} else {
350+
server.http(&addr)
351+
};
352+
338353
if let Err(e) = rv {
339354
printer
340355
.println_err(

0 commit comments

Comments
 (0)