worker_plus_sys/
request_init.rs1use wasm_bindgen::prelude::*;
2
3use crate::abort::AbortSignal;
4
5#[wasm_bindgen]
6extern "C" {
7 # [wasm_bindgen (extends = :: js_sys :: Object , js_name = RequestInit)]
8 #[derive(Debug, Clone, PartialEq, Eq)]
9 #[doc = "The `RequestInit` dictionary."]
10 pub type RequestInit;
11}
12impl RequestInit {
13 #[doc = "Construct a new `RequestInit`."]
14 pub fn new() -> Self {
15 ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new())
16 }
17 #[doc = "Change the `body` field of this object."]
18 pub fn body(&mut self, val: Option<&::wasm_bindgen::JsValue>) -> &mut Self {
19 let r = ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("body"), &JsValue::from(val));
20 debug_assert!(
21 r.is_ok(),
22 "setting properties should never fail on our dictionary objects"
23 );
24 let _ = r;
25 self
26 }
27
28 #[doc = "Change the `headers` field of this object."]
29 pub fn headers(&mut self, val: &::wasm_bindgen::JsValue) -> &mut Self {
30 let r = ::js_sys::Reflect::set(
31 self.as_ref(),
32 &JsValue::from("headers"),
33 &JsValue::from(val),
34 );
35 debug_assert!(
36 r.is_ok(),
37 "setting properties should never fail on our dictionary objects"
38 );
39 let _ = r;
40 self
41 }
42
43 #[doc = "Change the `method` field of this object."]
44 pub fn method(&mut self, val: &str) -> &mut Self {
45 let r =
46 ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("method"), &JsValue::from(val));
47 debug_assert!(
48 r.is_ok(),
49 "setting properties should never fail on our dictionary objects"
50 );
51 let _ = r;
52 self
53 }
54
55 #[doc = "Change the `redirect` field of this object."]
56 pub fn redirect(&mut self, val: RequestRedirect) -> &mut Self {
57 let r = ::js_sys::Reflect::set(
58 self.as_ref(),
59 &JsValue::from("redirect"),
60 &JsValue::from(val),
61 );
62 debug_assert!(
63 r.is_ok(),
64 "setting properties should never fail on our dictionary objects"
65 );
66 let _ = r;
67 self
68 }
69
70 #[doc = "Change the `signal` field of this object."]
71 pub fn signal(&mut self, val: Option<&AbortSignal>) -> &mut Self {
72 let r =
73 ::js_sys::Reflect::set(self.as_ref(), &JsValue::from("signal"), &JsValue::from(val));
74 debug_assert!(
75 r.is_ok(),
76 "setting properties should never fail on our dictionary objects"
77 );
78 let _ = r;
79 self
80 }
81}
82
83impl Default for RequestInit {
84 fn default() -> Self {
85 Self::new()
86 }
87}
88
89#[allow(clippy::manual_non_exhaustive)]
90#[wasm_bindgen]
91#[doc = "The `RequestRedirect` enum."]
92#[derive(Debug, Clone, Copy, PartialEq, Eq)]
93pub enum RequestRedirect {
94 Follow = "follow",
95 Error = "error",
96 Manual = "manual",
97}