mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
client: Port to Isahc 1.0
This commit is contained in:
parent
b49272b8ac
commit
4a407474e2
3 changed files with 8 additions and 6 deletions
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
isahc = "0.9.12"
|
||||
isahc = "1.1.0"
|
||||
musicus_database = { version = "0.1.0", path = "../musicus_database" }
|
||||
serde = { version = "1.0.117", features = ["derive"] }
|
||||
serde_json = "1.0.59"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use isahc::{AsyncBody, Request, Response};
|
||||
use isahc::http::StatusCode;
|
||||
use isahc::prelude::*;
|
||||
use serde::Serialize;
|
||||
|
|
@ -88,7 +89,7 @@ impl Client {
|
|||
|
||||
let success = match response.status() {
|
||||
StatusCode::OK => {
|
||||
let token = response.text_async().await?;
|
||||
let token = response.text().await?;
|
||||
self.token.replace(Some(token));
|
||||
true
|
||||
}
|
||||
|
|
@ -109,7 +110,7 @@ impl Client {
|
|||
.send_async()
|
||||
.await?;
|
||||
|
||||
let body = response.text_async().await?;
|
||||
let body = response.text().await?;
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
|
|
@ -128,7 +129,7 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
response.text_async().await?
|
||||
response.text().await?
|
||||
} else {
|
||||
let mut response = if self.login().await? {
|
||||
self.post_priv(url, body).await?
|
||||
|
|
@ -136,14 +137,14 @@ impl Client {
|
|||
Err(Error::LoginFailed)?
|
||||
};
|
||||
|
||||
response.text_async().await?
|
||||
response.text().await?
|
||||
};
|
||||
|
||||
Ok(body)
|
||||
}
|
||||
|
||||
/// 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 token = self.token()?;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::{Client, Result};
|
||||
use isahc::Request;
|
||||
use isahc::http::StatusCode;
|
||||
use isahc::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue