Repository: seanmonstar/reqwest (language: rust)

Issue:
Cloudflare workers bug since 0.11
#### Hey!

Looks like something is broken in Cloudflare workers runtime.

#### Minimal example:

```rust
#[wasm_bindgen]
pub async fn handle() -> String {
    let resp = match reqwest::get("https://wtfismyip.com/text").await {
        Ok(resp) => resp,
        Err(err) => return err.to_string(),
    };
    let text = resp.text().await.unwrap();
    text
}
```

With version 0.10 it works, but with 0.11 it falls into `Err` arm of the `match` statement.

#### Error message:
```
builder error: JsValue(Error: The 'credentials' field on 'RequestInitializerDict' is not implemented.
Error: The 'credentials' field on 'RequestInitializerDict' is not implemented.
    at worker.js:343:19
    at worker.js:222:22
    at <anonymous>:wasm-function[351]:0x36dc7
    at <anonymous>:wasm-function[49]:0xb3c4
    at <anonymous>:wasm-function[208]:0x31f93
    at <anonymous>:wasm-function[188]:0x30b0d
    at _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0dedee9324219338 (<anonymous>:wasm-function[435]:0x37e0e)
    at __wbg_adapter_26 (worker.js:208:10)
    at real (worker.js:193:20))
```


Discussion / hints:
Hm, that's probably because of https://github.com/seanmonstar/reqwest/pull/1227. Perhaps a fix is that we could change reqwest to have that internal type be an `Option<RequestCredentials>`, and so by default if you never set one, it should no longer try to set that field.
I'll give it a shot :)
@VictorBulba I've opened #1249, can you confirm it's fixed?

Fix patch:
diff --git a/src/wasm/client.rs b/src/wasm/client.rs
index 86ea04012..bf258c765 100644
--- a/src/wasm/client.rs
+++ b/src/wasm/client.rs
@@ -207,7 +207,9 @@ async fn fetch(req: Request) -> crate::Result<Response> {
         init.mode(web_sys::RequestMode::NoCors);
     }
 
-    init.credentials(req.credentials);
+    if let Some(creds) = req.credentials {
+        init.credentials(creds);
+    }
 
     if let Some(body) = req.body() {
         if !body.is_empty() {
diff --git a/src/wasm/request.rs b/src/wasm/request.rs
index de3691f08..35d0360ef 100644
--- a/src/wasm/request.rs
+++ b/src/wasm/request.rs
@@ -19,7 +19,7 @@ pub struct Request {
     headers: HeaderMap,
     body: Option<Body>,
     pub(super) cors: bool,
-    pub(super) credentials: RequestCredentials,
+    pub(super) credentials: Option<RequestCredentials>,
 }
 
 /// A builder to construct the properties of a `Request`.
@@ -38,7 +38,7 @@ impl Request {
             headers: HeaderMap::new(),
             body: None,
             cors: true,
-            credentials: RequestCredentials::SameOrigin,
+            credentials: None,
         }
     }
 
@@ -268,7 +268,7 @@ impl RequestBuilder {
     /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
     pub fn fetch_credentials_same_origin(mut self) -> RequestBuilder {
         if let Ok(ref mut req) = self.request {
-            req.credentials = RequestCredentials::SameOrigin;
+            req.credentials = Some(RequestCredentials::SameOrigin);
         }
         self
     }
@@ -284,7 +284,7 @@ impl RequestBuilder {
     /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
     pub fn fetch_credentials_include(mut self) -> RequestBuilder {
         if let Ok(ref mut req) = self.request {
-            req.credentials = RequestCredentials::Include;
+            req.credentials = Some(RequestCredentials::Include);
         }
         self
     }
@@ -300,7 +300,7 @@ impl RequestBuilder {
     /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
     pub fn fetch_credentials_omit(mut self) -> RequestBuilder {
         if let Ok(ref mut req) = self.request {
-            req.credentials = RequestCredentials::Omit;
+            req.credentials = Some(RequestCredentials::Omit);
         }
         self
     }
@@ -383,7 +383,7 @@ where
             headers,
             body: Some(body.into()),
             cors: true,
-            credentials: RequestCredentials::SameOrigin,
+            credentials: None,
         })
     }
 }


Test patch: