Repository: seanmonstar/reqwest (language: rust)

Issue:
impl TryFrom<http::Request<T>> for reqwest::Request is not available on wasm
Title pretty much says it all. It would be nice if this trait implementation could be made available for the wasm target.


Discussion / hints:

Fix patch:
diff --git a/src/wasm/request.rs b/src/wasm/request.rs
index 976ddfac2..7b6ae27f6 100644
--- a/src/wasm/request.rs
+++ b/src/wasm/request.rs
@@ -1,7 +1,7 @@
 use std::convert::TryFrom;
 use std::fmt;
 
-use http::Method;
+use http::{request::Parts, Method, Request as HttpRequest};
 use url::Url;
 #[cfg(feature = "json")]
 use serde_json;
@@ -300,3 +300,28 @@ fn fmt_request_fields<'a, 'b>(
         .field("url", &req.url)
         .field("headers", &req.headers)
 }
+
+impl<T> TryFrom<HttpRequest<T>> for Request
+where
+    T: Into<Body>,
+{
+    type Error = crate::Error;
+
+    fn try_from(req: HttpRequest<T>) -> crate::Result<Self> {
+        let (parts, body) = req.into_parts();
+        let Parts {
+            method,
+            uri,
+            headers,
+            ..
+        } = parts;
+        let url = Url::parse(&uri.to_string()).map_err(crate::error::builder)?;
+        Ok(Request {
+            method,
+            url,
+            headers,
+            body: Some(body.into()),
+            cors: true,
+        })
+    }
+}


Test patch: