diff --git a/src/lib.rs b/src/lib.rs index 274ec3a..8db0fd7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -202,4 +202,12 @@ mod tests { ); assert_eq!("text/html", resp.content_type()); } + + #[test] + #[cfg(feature = "tls")] + fn connect_https_invalid_name() { + let resp = get("https://example.com{REQUEST_URI}/").call(); + assert_eq!(400, resp.status()); + assert!(resp.synthetic()); + } } diff --git a/src/stream.rs b/src/stream.rs index a6b0d45..b4bf0e2 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -156,7 +156,8 @@ pub(crate) fn connect_https(unit: &Unit) -> Result { let hostname = unit.url.host_str().unwrap(); let port = unit.url.port().unwrap_or(443); - let sni = webpki::DNSNameRef::try_from_ascii_str(hostname).unwrap(); + let sni = webpki::DNSNameRef::try_from_ascii_str(hostname) + .map_err(|err| Error::DnsFailed(err.to_string()))?; let sess = rustls::ClientSession::new(&*TLS_CONF, sni); let sock = connect_host(unit, hostname, port)?;