1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use wasm_bindgen::prelude::*;

use crate::types::IncomingRequestCfProperties;

mod glue {
    use super::*;

    #[wasm_bindgen]
    extern "C" {
        #[wasm_bindgen]
        pub type Request;

        #[wasm_bindgen(method, getter)]
        pub fn cf(this: &Request) -> Option<IncomingRequestCfProperties>;
    }
}

pub trait RequestExt {
    /// Get the Cloudflare Properties from this request
    fn cf(&self) -> Option<IncomingRequestCfProperties>;
}

impl RequestExt for web_sys::Request {
    fn cf(&self) -> Option<IncomingRequestCfProperties> {
        self.unchecked_ref::<glue::Request>().cf()
    }
}