worker_sys/ext/
response_init.rs

1use wasm_bindgen::prelude::*;
2
3pub trait ResponseInitExt {
4    /// Change the `webSocket` field of this object.
5    fn websocket(&mut self, val: &web_sys::WebSocket) -> Result<&mut Self, JsValue>;
6
7    /// Change the `encodeBody` field of this object.
8    fn encode_body(&mut self, val: &str) -> Result<&mut Self, JsValue>;
9
10    /// Change the `cf` field of this object.
11    fn cf(&mut self, val: &JsValue) -> Result<&mut Self, JsValue>;
12}
13
14impl ResponseInitExt for web_sys::ResponseInit {
15    fn websocket(&mut self, val: &web_sys::WebSocket) -> Result<&mut Self, JsValue> {
16        js_sys::Reflect::set(self.as_ref(), &JsValue::from("webSocket"), val.as_ref())?;
17        Ok(self)
18    }
19
20    fn encode_body(&mut self, val: &str) -> Result<&mut Self, JsValue> {
21        js_sys::Reflect::set(
22            self.as_ref(),
23            &JsValue::from("encodeBody"),
24            &JsValue::from(val),
25        )?;
26        Ok(self)
27    }
28
29    fn cf(&mut self, val: &JsValue) -> Result<&mut Self, JsValue> {
30        js_sys::Reflect::set(self.as_ref(), &JsValue::from("cf"), val)?;
31        Ok(self)
32    }
33}