but safer

This commit is contained in:
psykose 2024-10-31 21:54:33 +01:00
parent b3b0160497
commit 2e4778f2f9

View file

@ -49,11 +49,7 @@ pub struct Client {
impl Client { impl Client {
pub fn new(url: &str, username: &str, token: &str, salt: &str) -> Result<Self, Error> { pub fn new(url: &str, username: &str, token: &str, salt: &str) -> Result<Self, Error> {
Ok(Client { let base_url = reqwest::Url::parse_with_params(
client: reqwest::Client::builder()
.user_agent("audrey/linux") // Audrey.Const.user_agent
.build()?,
base_url: reqwest::Url::parse_with_params(
url, url,
&[ &[
("u", username), ("u", username),
@ -64,7 +60,17 @@ impl Client {
("f", "json"), ("f", "json"),
], ],
) )
.map_err(|err| Error::UrlParseError(err.to_string()))?, .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,
}) })
} }