client: Port to Isahc 1.0

This commit is contained in:
Elias Projahn 2021-02-06 17:20:41 +01:00
parent b49272b8ac
commit 4a407474e2
3 changed files with 8 additions and 6 deletions

View file

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
isahc = "0.9.12" isahc = "1.1.0"
musicus_database = { version = "0.1.0", path = "../musicus_database" } musicus_database = { version = "0.1.0", path = "../musicus_database" }
serde = { version = "1.0.117", features = ["derive"] } serde = { version = "1.0.117", features = ["derive"] }
serde_json = "1.0.59" serde_json = "1.0.59"

View file

@ -1,3 +1,4 @@
use isahc::{AsyncBody, Request, Response};
use isahc::http::StatusCode; use isahc::http::StatusCode;
use isahc::prelude::*; use isahc::prelude::*;
use serde::Serialize; use serde::Serialize;
@ -88,7 +89,7 @@ impl Client {
let success = match response.status() { let success = match response.status() {
StatusCode::OK => { StatusCode::OK => {
let token = response.text_async().await?; let token = response.text().await?;
self.token.replace(Some(token)); self.token.replace(Some(token));
true true
} }
@ -109,7 +110,7 @@ impl Client {
.send_async() .send_async()
.await?; .await?;
let body = response.text_async().await?; let body = response.text().await?;
Ok(body) Ok(body)
} }
@ -128,7 +129,7 @@ impl Client {
} }
} }
response.text_async().await? response.text().await?
} else { } else {
let mut response = if self.login().await? { let mut response = if self.login().await? {
self.post_priv(url, body).await? self.post_priv(url, body).await?
@ -136,14 +137,14 @@ impl Client {
Err(Error::LoginFailed)? Err(Error::LoginFailed)?
}; };
response.text_async().await? response.text().await?
}; };
Ok(body) Ok(body)
} }
/// Post something to the server assuming there is a valid login token. /// Post something to the server assuming there is a valid login token.
async fn post_priv(&self, url: &str, body: String) -> Result<Response<Body>> { async fn post_priv(&self, url: &str, body: String) -> Result<Response<AsyncBody>> {
let server_url = self.server_url()?; let server_url = self.server_url()?;
let token = self.token()?; let token = self.token()?;

View file

@ -1,4 +1,5 @@
use crate::{Client, Result}; use crate::{Client, Result};
use isahc::Request;
use isahc::http::StatusCode; use isahc::http::StatusCode;
use isahc::prelude::*; use isahc::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};