but safer
This commit is contained in:
parent
b3b0160497
commit
2e4778f2f9
1 changed files with 18 additions and 12 deletions
|
@ -49,11 +49,7 @@ pub struct Client {
|
|||
|
||||
impl Client {
|
||||
pub fn new(url: &str, username: &str, token: &str, salt: &str) -> Result<Self, Error> {
|
||||
Ok(Client {
|
||||
client: reqwest::Client::builder()
|
||||
.user_agent("audrey/linux") // Audrey.Const.user_agent
|
||||
.build()?,
|
||||
base_url: reqwest::Url::parse_with_params(
|
||||
let base_url = reqwest::Url::parse_with_params(
|
||||
url,
|
||||
&[
|
||||
("u", username),
|
||||
|
@ -64,7 +60,17 @@ impl Client {
|
|||
("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,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue