diff --git a/Cargo.toml b/Cargo.toml index b107846..710b593 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,10 @@ exclude = [ "img/*" ] +[features] +tls = [] +default =[] + [profile.release] lto = true codegen-units = 1 diff --git a/src/gopher.rs b/src/gopher.rs index 909215c..fc962ea 100644 --- a/src/gopher.rs +++ b/src/gopher.rs @@ -111,7 +111,7 @@ pub fn request(host: &str, port: &str, selector: &str, try_tls: bool) -> Result< .and_then(|mut socks| socks.next().ok_or_else(|| error!("Can't create socket")))?; // attempt tls connection - if try_tls { + if cfg!(feature = "tls") && try_tls { if let Ok(connector) = TlsConnector::new() { let stream = TcpStream::connect_timeout(&sock, TCP_TIMEOUT_DURATION)?; stream.set_read_timeout(Some(TCP_TIMEOUT_DURATION))?; diff --git a/src/main.rs b/src/main.rs index 254a317..9bbfd07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -30,7 +30,13 @@ fn run() -> i32 { } } "-l" | "--local" | "-local" => url = "gopher://127.0.0.1:7070", - "-t" | "--tls" | "-tls" => tls = true, + "-t" | "--tls" | "-tls" => { + tls = true; + if !cfg!(feature = "tls") { + eprintln!("phetch was compiled without TLS support"); + return 1; + } + } arg => { if arg.starts_with('-') { eprintln!("unknown flag: {}\n", url);