mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-26 20:10:31 +00:00
webrtchttp: whipsink: construct TURN URL correctly
Right now the code manually pieces together the components in a String for efficiency. When credentials contain special characters this can result in invalid URLs, so do it the proper way (with Url::parse + format) to make sure components are escaped as needed. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/949>
This commit is contained in:
parent
9fb058d5bc
commit
db39370701
1 changed files with 10 additions and 17 deletions
|
@ -161,34 +161,27 @@ pub fn set_ice_servers(
|
|||
// for changing <scheme>:<host> to <scheme>://<user>:<password>@<host>.
|
||||
// So preferred to use the String rather
|
||||
|
||||
let mut ice_server_url;
|
||||
|
||||
// check if uri has ://
|
||||
if link.uri.has_authority() {
|
||||
let ice_server_url = if link.uri.has_authority() {
|
||||
// use raw_uri as is
|
||||
// username and password in the link.uri.params ignored
|
||||
ice_server_url = link.raw_uri.as_str().to_string();
|
||||
link.uri.clone()
|
||||
} else {
|
||||
// No builder pattern is provided by reqwest::Url. Use string operation.
|
||||
// construct url as '<scheme>://<user:pass>@<url>'
|
||||
ice_server_url = format!("{}://", link.uri.scheme());
|
||||
let url = format!("{}://{}", link.uri.scheme(), link.uri.path());
|
||||
|
||||
let Ok(mut new_url) = reqwest::Url::parse(url.as_str()) else { continue };
|
||||
|
||||
if let Some(user) = link.params.get("username") {
|
||||
ice_server_url += user.as_str();
|
||||
new_url.set_username(user.as_str()).unwrap();
|
||||
if let Some(pass) = link.params.get("credential") {
|
||||
ice_server_url = ice_server_url + ":" + pass.as_str();
|
||||
new_url.set_password(Some(pass.as_str())).unwrap();
|
||||
}
|
||||
ice_server_url += "@";
|
||||
}
|
||||
|
||||
// the raw_uri contains the ice-server in the form <scheme>:<url>
|
||||
// so strip the scheme and the ':' from the beginning of raw_uri and use
|
||||
// the rest of raw_uri to append it the url which will be in the form
|
||||
// <scheme>://<user:pass>@<url> as expected
|
||||
ice_server_url += link
|
||||
.raw_uri
|
||||
.strip_prefix((link.uri.scheme().to_owned() + ":").as_str())
|
||||
.expect("strip 'scheme:' from raw uri");
|
||||
}
|
||||
new_url
|
||||
};
|
||||
|
||||
// It's nicer to not collapse the `else if` and its inner `if`
|
||||
#[allow(clippy::collapsible_if)]
|
||||
|
|
Loading…
Reference in a new issue