Repository: seanmonstar/reqwest (language: rust)

Issue:
Support for fetching blob URLs in Rust WebAssembly using reqwest
I'm trying to use reqwest in Rust WebAssembly to fetch a blob URL, but I'm getting an error stating "URL scheme is not allowed".

Currently, it seems that the only way to fetch a blob URL in Rust WebAssembly is to use the web_sys crate to fetch the blob.

It would be great if reqwest could support fetching blob URLs in Rust WebAssembly.


Discussion / hints:

Fix patch:
diff --git a/src/into_url.rs b/src/into_url.rs
index ef0db9495..d60f5c952 100644
--- a/src/into_url.rs
+++ b/src/into_url.rs
@@ -21,6 +21,16 @@ pub trait IntoUrlSealed {
 
 impl IntoUrlSealed for Url {
     fn into_url(self) -> crate::Result<Url> {
+        // With blob url the `self.has_host()` check is always false, so we
+        // remove the `blob:` scheme and check again if the url is valid.
+        #[cfg(target_arch = "wasm32")]
+        if self.scheme() == "blob"
+            && self.path().starts_with("http") // Check if the path starts with http or https to avoid validating a `blob:blob:...` url.
+            && self.as_str()[5..].into_url().is_ok()
+        {
+            return Ok(self);
+        }
+
         if self.has_host() {
             Ok(self)
         } else {
@@ -87,4 +97,24 @@ mod tests {
             "builder error for url (file:///etc/hosts): URL scheme is not allowed"
         );
     }
+
+    #[test]
+    fn into_url_blob_scheme() {
+        let err = "blob:https://example.com".into_url().unwrap_err();
+        assert_eq!(
+            err.to_string(),
+            "builder error for url (blob:https://example.com): URL scheme is not allowed"
+        );
+    }
+
+    if_wasm! {
+        use wasm_bindgen_test::*;
+
+        #[wasm_bindgen_test]
+        fn into_url_blob_scheme_wasm() {
+            let url = "blob:http://example.com".into_url().unwrap();
+
+            assert_eq!(url.as_str(), "blob:http://example.com");
+        }
+    }
 }


Test patch: