From 480ff9680c29bd2ffb7d9de47769a73c1f5e1d22 Mon Sep 17 00:00:00 2001 From: hongcha Date: Mon, 5 Feb 2024 00:42:04 +0800 Subject: [PATCH] fix: resource url --- Cargo.lock | 1 + libs/libwish/Cargo.toml | 1 + libs/libwish/src/lib.rs | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cfe982f..2754c943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1235,6 +1235,7 @@ dependencies = [ "base64 0.21.4", "parse_link_header", "reqwest", + "url", "webrtc", ] diff --git a/libs/libwish/Cargo.toml b/libs/libwish/Cargo.toml index f69a092d..aef34e7b 100644 --- a/libs/libwish/Cargo.toml +++ b/libs/libwish/Cargo.toml @@ -15,3 +15,4 @@ reqwest = { version = "0.11.20", features = [ ], default-features = false } parse_link_header = "0.3" base64 = "0.21.3" +url = "2.4.1" diff --git a/libs/libwish/src/lib.rs b/libs/libwish/src/lib.rs index 184a2579..07f7ca8e 100644 --- a/libs/libwish/src/lib.rs +++ b/libs/libwish/src/lib.rs @@ -5,6 +5,7 @@ use reqwest::{ Body, Method, Response, StatusCode, }; use std::str::FromStr; +use url::Url; use webrtc::{ ice_transport::ice_server::RTCIceServer, peer_connection::sdp::session_description::RTCSessionDescription, @@ -62,7 +63,16 @@ impl Client { .ok_or_else(|| anyhow::anyhow!("Response missing location header"))? .to_str()? .to_owned(); - self.resource_url = Some(resource_url); + let mut url = Url::parse(self.url.as_str())?; + match Url::parse(resource_url.as_str()) { + Ok(url) => { + self.resource_url = Some(url.into()); + } + Err(_) => { + url.set_path(resource_url.as_str()); + self.resource_url = Some(url.into()); + } + } let ice_servers = Self::parse_ide_servers(&response)?; let sdp = RTCSessionDescription::answer(String::from_utf8(response.bytes().await?.to_vec())?)?; @@ -79,11 +89,7 @@ impl Client { continue; } ice_servers.push(RTCIceServer { - urls: vec![link - .uri - .to_string() - .replacen("://", ":", 1) - .replace('/', "")], + urls: vec![link.uri.to_string()], username: link.queries.remove("username").unwrap_or("".to_owned()), credential: link.queries.remove("credential").unwrap_or("".to_owned()), credential_type: link