|
@@ -5,6 +5,7 @@ use std::str::FromStr;
|
|
|
|
|
|
|
|
use crate::{
|
|
use crate::{
|
|
|
auth::{Auth, BasicAuth, OAuth},
|
|
auth::{Auth, BasicAuth, OAuth},
|
|
|
|
|
+ error::AppError,
|
|
|
request::{ctype::ContentType, url::RequestUrl},
|
|
request::{ctype::ContentType, url::RequestUrl},
|
|
|
workspace::WorkspaceEntryBase,
|
|
workspace::WorkspaceEntryBase,
|
|
|
AppResult,
|
|
AppResult,
|
|
@@ -25,8 +26,6 @@ pub const DEFAULT_HEADERS: &'static [(&'static str, &'static str)] = &[
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
pub async fn send(client: reqwest::Client, req: HttpRequestParameters) -> AppResult<HttpResponse> {
|
|
pub async fn send(client: reqwest::Client, req: HttpRequestParameters) -> AppResult<HttpResponse> {
|
|
|
- dbg!(&req);
|
|
|
|
|
-
|
|
|
|
|
let HttpRequestParameters {
|
|
let HttpRequestParameters {
|
|
|
url,
|
|
url,
|
|
|
method,
|
|
method,
|
|
@@ -44,10 +43,20 @@ pub async fn send(client: reqwest::Client, req: HttpRequestParameters) -> AppRes
|
|
|
Some(body) => {
|
|
Some(body) => {
|
|
|
match body.ty {
|
|
match body.ty {
|
|
|
ContentType::Text => insert_ct_if_missing(&mut headers, "text/plain"),
|
|
ContentType::Text => insert_ct_if_missing(&mut headers, "text/plain"),
|
|
|
- ContentType::Json => insert_ct_if_missing(&mut headers, "application/json"),
|
|
|
|
|
- ContentType::Xml => insert_ct_if_missing(&mut headers, "application/xml"),
|
|
|
|
|
|
|
+ ContentType::Json => {
|
|
|
|
|
+ insert_ct_if_missing(&mut headers, "application/json");
|
|
|
|
|
+ serde_json::from_str::<serde_json::Value>(&body.content)?;
|
|
|
|
|
+ }
|
|
|
|
|
+ ContentType::Xml => {
|
|
|
|
|
+ insert_ct_if_missing(&mut headers, "application/xml");
|
|
|
|
|
+ roxmltree::Document::parse(&body.content)?;
|
|
|
|
|
+ }
|
|
|
|
|
+ ContentType::FormUrlEncoded => {
|
|
|
|
|
+ serde_urlencoded::from_str::<Vec<(String, String)>>(&body.content)
|
|
|
|
|
+ .map_err(|e| AppError::SerdeUrl(e.to_string()))?;
|
|
|
|
|
+ }
|
|
|
// Handled by reqwest
|
|
// Handled by reqwest
|
|
|
- ContentType::FormData | ContentType::FormUrlEncoded => {}
|
|
|
|
|
|
|
+ ContentType::FormData => {}
|
|
|
};
|
|
};
|
|
|
Some(Body::from(body.content))
|
|
Some(Body::from(body.content))
|
|
|
}
|
|
}
|
|
@@ -60,7 +69,11 @@ pub async fn send(client: reqwest::Client, req: HttpRequestParameters) -> AppRes
|
|
|
req = req.body(body)
|
|
req = req.body(body)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let res = match req.send().await {
|
|
|
|
|
|
|
+ let req = req.build().unwrap();
|
|
|
|
|
+
|
|
|
|
|
+ dbg!(&req);
|
|
|
|
|
+
|
|
|
|
|
+ let res = match client.execute(req).await {
|
|
|
Ok(res) => {
|
|
Ok(res) => {
|
|
|
log::debug!(
|
|
log::debug!(
|
|
|
"{} {} {:?} {:#?}",
|
|
"{} {} {:?} {:#?}",
|