expression
Reject a URL passed as ServerName
The expected server identity is a host name or IP address, not an entire URL. Use a reviewed URL parser to extract the intended host from a legitimate URL. Do not remove arbitrary punctuation to force an invalid name to parse. External crate example; candidate dependency is not approved for deployment. Expected stdout (not executed): true Common mistake: Passing scheme, port or path as part of the certificate identity.
Formal Syntax & Structure
rust syntaxrust
ServerName::try_from("https://example.com/path")Working Example
Example Snippetrust
fn main() { use rustls::pki_types::ServerName; println!("{}", ServerName::try_from("https://example.com/path").is_err());}