Skip to content

Commit

Permalink
Include 'mode' on native too
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Feb 17, 2024
1 parent 02be481 commit 3b6382e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions ehttp/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl<'h> IntoIterator for &'h Headers {
// ----------------------------------------------------------------------------

/// Determine if cross-origin requests lead to valid responses.
///
/// Based on <https://developer.mozilla.org/en-US/docs/Web/API/Request/mode>
#[cfg(target_arch = "wasm32")]
#[derive(Default, Clone, Copy, Debug)]
pub enum Mode {
/// If a request is made to another origin with this mode set, the result is an error.
Expand Down Expand Up @@ -141,8 +141,9 @@ pub struct Request {
/// ("Accept", "*/*"), …
pub headers: Headers,

/// Request mode used on fetch. Only available on wasm builds
#[cfg(target_arch = "wasm32")]
/// Request mode used on fetch.
///
/// Used on Web to control CORS.
pub mode: Mode,
}

Expand All @@ -155,7 +156,6 @@ impl Request {
url: url.to_string(),
body: vec![],
headers: Headers::new(&[("Accept", "*/*")]),
#[cfg(target_arch = "wasm32")]
mode: Mode::default(),
}
}
Expand All @@ -168,7 +168,6 @@ impl Request {
url: url.to_string(),
body: vec![],
headers: Headers::new(&[("Accept", "*/*")]),
#[cfg(target_arch = "wasm32")]
mode: Mode::default(),
}
}
Expand All @@ -184,7 +183,6 @@ impl Request {
("Accept", "*/*"),
("Content-Type", "text/plain; charset=utf-8"),
]),
#[cfg(target_arch = "wasm32")]
mode: Mode::default(),
}
}
Expand Down Expand Up @@ -219,7 +217,6 @@ impl Request {
url: url.to_string(),
body: data,
headers: Headers::new(&[("Accept", "*/*"), ("Content-Type", content_type.as_str())]),
#[cfg(target_arch = "wasm32")]
mode: Mode::default(),
}
}
Expand All @@ -236,7 +233,6 @@ impl Request {
url: url.to_string(),
body: serde_json::to_string(body)?.into_bytes(),
headers: Headers::new(&[("Accept", "*/*"), ("Content-Type", "application/json")]),
#[cfg(target_arch = "wasm32")]
mode: Mode::default(),
})
}
Expand Down

0 comments on commit 3b6382e

Please sign in to comment.