housleyjk / ws-rs

Lightweight, event-driven WebSockets for Rust.
MIT License
1.46k stars 219 forks source link

WSS always fails if ip addr used #302

Closed nree closed 4 years ago

nree commented 4 years ago

ERROR ws::handler] WS Error <Protocol>: Unable to parse domain from wss://127.0.0.1:55037/. Needed for SSL.

Only when using wss & if using 'localhost' ok. Sometimes you don't want to use 'localhost' , you want to be specific with ip addr.

Bad code here: https://github.com/housleyjk/ws-rs/blob/4a981affa5281ea742fbaf4f4f4120876cd2b5b2/src/handler.rs#L294

Assumes everything is a domain or fail. Doesn't check if ipaddr

Doc for domain:

pub fn domain(&self) -> Option<&str>
If this URL has a host and it is a domain name (not an IP address), return it.

# Examples

use url::Url;
let url = Url::parse("https://127.0.0.1/")?;
assert_eq!(url.domain(), None);

let url = Url::parse("mailto:rms@example.net")?;
assert_eq!(url.domain(), None);

let url = Url::parse("https://example.com/")?;
assert_eq!(url.domain(), Some("example.com"));
Darkspirit commented 4 years ago

Current implementation is a wise choice. It's best practice to use TLS certificates with domain names for compatibility (dualstack IP) and security reasons (ACME DNS challenge). Please close.

nree commented 4 years ago

ok, that seems fair, though I think the error message could be better. Seems like a parsing error at first glance (see original title of issue).