[fractal] Remove "json" feature in reqwest



commit 72a73a84d3e639191341b63006c69f98130e8b0f
Author: Alejandro Domínguez <adomu net-c com>
Date:   Thu Oct 1 11:35:16 2020 +0200

    Remove "json" feature in reqwest

 Cargo.lock                                         |  1 -
 fractal-gtk/Cargo.toml                             |  2 +-
 .../identity/association/msisdn/submit_token.rs    |  4 +++-
 fractal-gtk/src/api/r0/account/deactivate.rs       |  4 +++-
 fractal-gtk/src/api/r0/account/login.rs            |  4 +++-
 fractal-gtk/src/api/r0/contact/create.rs           |  4 +++-
 fractal-gtk/src/api/r0/contact/delete.rs           |  4 +++-
 fractal-gtk/src/backend/register.rs                | 28 +++++++++++++++++-----
 fractal-gtk/src/backend/user.rs                    | 19 +++++++++++----
 9 files changed, 53 insertions(+), 17 deletions(-)
---
diff --git a/Cargo.lock b/Cargo.lock
index 0f942936..572e0868 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2828,7 +2828,6 @@ dependencies = [
  "percent-encoding",
  "pin-project-lite 0.2.0",
  "serde",
- "serde_json",
  "serde_urlencoded",
  "tokio",
  "tokio-socks",
diff --git a/fractal-gtk/Cargo.toml b/fractal-gtk/Cargo.toml
index 2e20b849..6a8ed178 100644
--- a/fractal-gtk/Cargo.toml
+++ b/fractal-gtk/Cargo.toml
@@ -81,7 +81,7 @@ features = ["rt-threaded", "time"]
 
 [dependencies.reqwest]
 version = "0.10.3"
-features = ["json", "socks"]
+features = ["socks"]
 
 [dependencies.url]
 version = "2.1.1"
diff --git a/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs 
b/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
index 1b89d662..b6de10ed 100644
--- a/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
+++ b/fractal-gtk/src/api/identity/association/msisdn/submit_token.rs
@@ -21,5 +21,7 @@ pub fn request(base: Url, body: &Body) -> Result<Request, Error> {
         .join("_matrix/identity/api/v1/validate/msisdn/submitToken")
         .expect("Malformed URL in msisdn submit_token");
 
-    Client::new().post(url).json(body).build()
+    let data = serde_json::to_vec(body).unwrap();
+
+    Client::new().post(url).body(data).build()
 }
diff --git a/fractal-gtk/src/api/r0/account/deactivate.rs b/fractal-gtk/src/api/r0/account/deactivate.rs
index dc7486df..2dd9ef1e 100644
--- a/fractal-gtk/src/api/r0/account/deactivate.rs
+++ b/fractal-gtk/src/api/r0/account/deactivate.rs
@@ -22,5 +22,7 @@ pub fn request(base: Url, params: &Parameters, body: &Body) -> Result<Request, E
         .join("_matrix/client/r0/account/deactivate")
         .expect("Malformed URL in deactivate");
 
-    Client::new().post(url).query(params).json(body).build()
+    let data = serde_json::to_vec(body).unwrap();
+
+    Client::new().post(url).query(params).body(data).build()
 }
diff --git a/fractal-gtk/src/api/r0/account/login.rs b/fractal-gtk/src/api/r0/account/login.rs
index 3795581c..adeb889b 100644
--- a/fractal-gtk/src/api/r0/account/login.rs
+++ b/fractal-gtk/src/api/r0/account/login.rs
@@ -42,5 +42,7 @@ pub fn request(base: Url, body: &Body) -> Result<Request, Error> {
         .join("_matrix/client/r0/login")
         .expect("Malformed URL in login");
 
-    Client::new().post(url).json(body).build()
+    let data = serde_json::to_vec(body).unwrap();
+
+    Client::new().post(url).body(data).build()
 }
diff --git a/fractal-gtk/src/api/r0/contact/create.rs b/fractal-gtk/src/api/r0/contact/create.rs
index 79ded7ae..df825247 100644
--- a/fractal-gtk/src/api/r0/contact/create.rs
+++ b/fractal-gtk/src/api/r0/contact/create.rs
@@ -24,5 +24,7 @@ pub fn request(base: Url, params: &Parameters, body: &Body) -> Result<Request, E
         .join("_matrix/client/r0/account/3pid")
         .expect("Malformed URL in contact create");
 
-    Client::new().post(url).query(params).json(body).build()
+    let data = serde_json::to_vec(body).unwrap();
+
+    Client::new().post(url).query(params).body(data).build()
 }
diff --git a/fractal-gtk/src/api/r0/contact/delete.rs b/fractal-gtk/src/api/r0/contact/delete.rs
index 968d775f..b9ab8d7b 100644
--- a/fractal-gtk/src/api/r0/contact/delete.rs
+++ b/fractal-gtk/src/api/r0/contact/delete.rs
@@ -22,5 +22,7 @@ pub fn request(base: Url, params: &Parameters, body: &Body) -> Result<Request, E
         .join("_matrix/client/r0/account/3pid/delete")
         .expect("Malformed URL in contact delete");
 
-    Client::new().post(url).query(params).json(body).build()
+    let data = serde_json::to_vec(body).unwrap();
+
+    Client::new().post(url).query(params).body(data).build()
 }
diff --git a/fractal-gtk/src/backend/register.rs b/fractal-gtk/src/backend/register.rs
index 650a6338..b5cd3e7f 100644
--- a/fractal-gtk/src/backend/register.rs
+++ b/fractal-gtk/src/backend/register.rs
@@ -32,6 +32,12 @@ impl From<ReqwestError> for LoginError {
     }
 }
 
+impl From<serde_json::Error> for LoginError {
+    fn from(_: serde_json::Error) -> Self {
+        Self
+    }
+}
+
 impl HandleError for LoginError {
     fn handle_error(&self) {
         let error = i18n("Can’t login, try again");
@@ -67,13 +73,15 @@ pub async fn login(
     };
 
     let request = login_req(server, &body)?;
-    let response: LoginResponse = HTTP_CLIENT
+    let response_raw = HTTP_CLIENT
         .get_client()
         .execute(request)
         .await?
-        .json()
+        .bytes()
         .await?;
 
+    let response: LoginResponse = serde_json::from_slice(&response_raw)?;
+
     if let (Some(tk), Some(uid)) = (response.access_token, response.user_id) {
         Ok((uid, tk, response.device_id))
     } else {
@@ -104,6 +112,7 @@ pub async fn logout(server: Url, access_token: AccessToken) -> Result<(), Logout
 #[derive(Debug)]
 pub enum GetWellKnownError {
     Reqwest(ReqwestError),
+    Json(serde_json::Error),
     ParseUrl(UrlError),
 }
 
@@ -113,6 +122,12 @@ impl From<ReqwestError> for GetWellKnownError {
     }
 }
 
+impl From<serde_json::Error> for GetWellKnownError {
+    fn from(err: serde_json::Error) -> Self {
+        Self::Json(err)
+    }
+}
+
 impl From<UrlError> for GetWellKnownError {
     fn from(err: UrlError) -> Self {
         Self::ParseUrl(err)
@@ -122,11 +137,12 @@ impl From<UrlError> for GetWellKnownError {
 pub async fn get_well_known(domain: Url) -> Result<DomainInfoResponse, GetWellKnownError> {
     let request = domain_info(domain)?;
 
-    HTTP_CLIENT
+    let response_raw = HTTP_CLIENT
         .get_client()
         .execute(request)
         .await?
-        .json()
-        .await
-        .map_err(Into::into)
+        .bytes()
+        .await?;
+
+    serde_json::from_slice(&response_raw).map_err(Into::into)
 }
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index 33bab1aa..3e91621c 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -257,11 +257,20 @@ pub async fn add_threepid(
 }
 
 #[derive(Debug)]
-pub struct SubmitPhoneTokenError(ReqwestError);
+pub enum SubmitPhoneTokenError {
+    Reqwest(ReqwestError),
+    Json(serde_json::Error),
+}
 
 impl From<ReqwestError> for SubmitPhoneTokenError {
     fn from(err: ReqwestError) -> Self {
-        Self(err)
+        Self::Reqwest(err)
+    }
+}
+
+impl From<serde_json::Error> for SubmitPhoneTokenError {
+    fn from(err: serde_json::Error) -> Self {
+        Self::Json(err)
     }
 }
 
@@ -280,13 +289,15 @@ pub async fn submit_phone_token(
     };
 
     let request = submit_phone_token_req(base, &body)?;
-    let response: SubmitPhoneTokenResponse = HTTP_CLIENT
+    let response_raw = HTTP_CLIENT
         .get_client()
         .execute(request)
         .await?
-        .json()
+        .bytes()
         .await?;
 
+    let response: SubmitPhoneTokenResponse = serde_json::from_slice(&response_raw)?;
+
     Ok((Some(sid).filter(|_| response.success), client_secret))
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]