ehttp icon indicating copy to clipboard operation
ehttp copied to clipboard

Headers field unused on WASM

Open Strosel opened this issue 1 year ago • 1 comments

It seems that the headers field of the Request struct remains unused when compiling to WASM. From what I can tell this is because they are set via a getter here and therefore remain unused.

From a quick glance at the web-sys docs the correct way to set headers is by passing a Headers struct to the RequestInit instead. I might be able to test this and make a PR later this week.

Strosel avatar Jun 05 '24 22:06 Strosel

@Strosel I got around this by using custom functions/implementations of Request

Post json content for exemple:

fn post_json(url: String, body: Vec<u8>) -> Request {
    Request {
        method: "POST".to_owned(),
        url: url,
        body,
        headers: Headers::new(&[
            ("Accept", "*/*"),
            ("Content-Type", "application/json; charset=utf-8"),
        ]),
        #[cfg(target_arch = "wasm32")]
        mode: Mode::default(),
    }
}

chianti-ga avatar Aug 09 '24 17:08 chianti-ga