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, }) }