emilk / ehttp

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

Conditional Compile Required for Requests #53

Closed cjs-axsh closed 7 months ago

cjs-axsh commented 7 months ago

This may be intended behavior since the suggestion in #51 seems to recommend it explicitly. But after #52, instantiating Request needs a conditional compile if targeting both wasm and native to account for the new mode field.

This was also more difficult to figure out than necessary because the docs don't have a wasm platform listed -- so the mode field is just not present anywhere on https://docs.rs/ehttp/latest/ehttp/struct.Request.html regardless of platform target choice.

The workaround of adding

#[cfg(target_arch = "wasm32")]
mode: ehttp::Mode::Cors,

to all Request instantiations is not all that bad, but the lack of documentation makes it more cumbersome than it needs to be. Maybe deriving default for Request would make it a little more clean, but still the lack of documentation seems to be the main issue.

I don't have any suggestions for a real fix, maybe something simple like adding a mode field for native as well? Anyway, feel free to close this issue if things are working as intended for everyone else.