diff --git a/rust/phoenix-channel/src/lib.rs b/rust/phoenix-channel/src/lib.rs index ca7d42726..1a328c233 100644 --- a/rust/phoenix-channel/src/lib.rs +++ b/rust/phoenix-channel/src/lib.rs @@ -246,7 +246,7 @@ where // We expose them to other components that deal with DNS stuff to ensure our domain always resolves to these IPs. let resolved_addresses = url .expose_secret() - .host() + .host_and_port() .to_socket_addrs()? .map(|addr| addr.ip()) .collect(); @@ -281,7 +281,7 @@ where /// The host we are connecting / connected to. pub fn server_host(&self) -> &str { - self.url_prototype.expose_secret().host() + self.url_prototype.expose_secret().host_and_port().0 } /// Join the provided room. @@ -364,7 +364,7 @@ where self.heartbeat.reset(); self.state = State::Connected(stream); - let host = self.url_prototype.expose_secret().host(); + let (host, _) = self.url_prototype.expose_secret().host_and_port(); tracing::info!(%host, "Connected to portal"); self.join(self.login, self.init_req.clone()); diff --git a/rust/phoenix-channel/src/login_url.rs b/rust/phoenix-channel/src/login_url.rs index 2c2a1e7a0..1c3915750 100644 --- a/rust/phoenix-channel/src/login_url.rs +++ b/rust/phoenix-channel/src/login_url.rs @@ -38,6 +38,7 @@ pub struct LoginUrl { // This is duplicated here because `Url::host` is fallible. // If we don't duplicate it, we'd have to do extra error handling in several places instead of just one place. host: String, + port: u16, phantom: PhantomData, } @@ -99,8 +100,11 @@ impl LoginUrl { device_info, )?; + let (host, port) = parse_host(&url)?; + Ok(LoginUrl { - host: parse_host(&url)?, + host, + port, url, phantom: PhantomData, }) @@ -129,8 +133,11 @@ impl LoginUrl { Default::default(), )?; + let (host, port) = parse_host(&url)?; + Ok(LoginUrl { - host: parse_host(&url)?, + host, + port, url, phantom: PhantomData, }) @@ -158,8 +165,11 @@ impl LoginUrl { Default::default(), )?; + let (host, port) = parse_host(&url)?; + Ok(LoginUrl { - host: parse_host(&url)?, + host, + port, url, phantom: PhantomData, }) @@ -180,18 +190,18 @@ where } impl LoginUrl { - pub fn host(&self) -> &str { - &self.host + pub fn host_and_port(&self) -> (&str, u16) { + (&self.host, self.port) } } /// Parse the host from a URL, including port if present. e.g. `example.com:8080`. -fn parse_host(url: &Url) -> Result> { +fn parse_host(url: &Url) -> Result<(String, u16), LoginUrlError> { let host = url.host_str().ok_or(LoginUrlError::MissingHost)?; Ok(match url.port() { - Some(p) => format!("{host}:{p}"), - None => host.to_owned(), + Some(p) => (host.to_owned(), p), + None => (host.to_owned(), 443), }) }