From 2e4778f2f9955b870e36822dd8c3ce5f7459a80c Mon Sep 17 00:00:00 2001 From: psykose Date: Thu, 31 Oct 2024 21:54:33 +0100 Subject: [PATCH] but safer --- src/subsonic.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/subsonic.rs b/src/subsonic.rs index c5dd0e4..25685eb 100644 --- a/src/subsonic.rs +++ b/src/subsonic.rs @@ -49,22 +49,28 @@ pub struct Client { impl Client { pub fn new(url: &str, username: &str, token: &str, salt: &str) -> Result { + let base_url = reqwest::Url::parse_with_params( + url, + &[ + ("u", username), + ("t", token), + ("s", salt), + ("v", "1.16.1"), + ("c", "eu.callcc.audrey"), + ("f", "json"), + ], + ) + .map_err(|err| Error::UrlParseError(err.to_string()))?; + + if base_url.scheme() != "http" && base_url.scheme() != "https" { + return Err(Error::UrlParseError("Url scheme is not HTTP(s)".into())); + } + Ok(Client { client: reqwest::Client::builder() .user_agent("audrey/linux") // Audrey.Const.user_agent .build()?, - base_url: reqwest::Url::parse_with_params( - url, - &[ - ("u", username), - ("t", token), - ("s", salt), - ("v", "1.16.1"), - ("c", "eu.callcc.audrey"), - ("f", "json"), - ], - ) - .map_err(|err| Error::UrlParseError(err.to_string()))?, + base_url, }) }