Implement Response::json for wasm32 target (#802)
This commit is contained in:
@@ -62,6 +62,9 @@ __internal_proxy_sys_no_cache = []
|
|||||||
http = "0.2"
|
http = "0.2"
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
bytes = "0.5"
|
bytes = "0.5"
|
||||||
|
serde = "1.0"
|
||||||
|
## json
|
||||||
|
serde_json = { version = "1.0", optional = true }
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
base64 = "0.11"
|
base64 = "0.11"
|
||||||
@@ -82,7 +85,6 @@ pin-project-lite = "0.1.1"
|
|||||||
|
|
||||||
# TODO: candidates for optional features
|
# TODO: candidates for optional features
|
||||||
|
|
||||||
serde = "1.0"
|
|
||||||
serde_urlencoded = "0.6.1"
|
serde_urlencoded = "0.6.1"
|
||||||
|
|
||||||
# Optional deps...
|
# Optional deps...
|
||||||
@@ -105,8 +107,6 @@ cookie_store = { version = "0.10", optional = true }
|
|||||||
## gzip
|
## gzip
|
||||||
async-compression = { version = "0.2.0", default-features = false, features = ["gzip", "stream"], optional = true }
|
async-compression = { version = "0.2.0", default-features = false, features = ["gzip", "stream"], optional = true }
|
||||||
|
|
||||||
## json
|
|
||||||
serde_json = { version = "1.0", optional = true }
|
|
||||||
|
|
||||||
## socks
|
## socks
|
||||||
tokio-socks = { version = "0.2", optional = true }
|
tokio-socks = { version = "0.2", optional = true }
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ use js_sys::Uint8Array;
|
|||||||
use http::{HeaderMap, StatusCode};
|
use http::{HeaderMap, StatusCode};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
#[cfg(feature = "json")]
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
/// A Response to a submitted `Request`.
|
/// A Response to a submitted `Request`.
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
http: http::Response<web_sys::Response>,
|
http: http::Response<web_sys::Response>,
|
||||||
@@ -56,8 +59,13 @@ impl Response {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// pub async fn json()
|
/// Try to deserialize the response body as JSON.
|
||||||
|
#[cfg(feature = "json")]
|
||||||
|
pub async fn json<T: DeserializeOwned>(self) -> crate::Result<T> {
|
||||||
|
let full = self.bytes().await?;
|
||||||
|
|
||||||
|
serde_json::from_slice(&full).map_err(crate::error::decode)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the response text.
|
/// Get the response text.
|
||||||
pub async fn text(self) -> crate::Result<String> {
|
pub async fn text(self) -> crate::Result<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user