Skip to content

Commit

Permalink
WASM: set RequestCredentials to None by default (seanmonstar#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensadiku authored Apr 21, 2021
1 parent 9293cd2 commit 42b3160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/wasm/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 6 additions & 6 deletions src/wasm/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -38,7 +38,7 @@ impl Request {
headers: HeaderMap::new(),
body: None,
cors: true,
credentials: RequestCredentials::SameOrigin,
credentials: None,
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -383,7 +383,7 @@ where
headers,
body: Some(body.into()),
cors: true,
credentials: RequestCredentials::SameOrigin,
credentials: None,
})
}
}

0 comments on commit 42b3160

Please sign in to comment.