emilk / ehttp

Minimal Rust HTTP client for both native and WASM
Apache License 2.0
316 stars 30 forks source link

Headers field unused on WASM #57

Open Strosel opened 3 months ago

Strosel commented 3 months ago

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.

chianti-ga commented 1 month ago

@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(),
    }
}