bevy_web_asset
bevy_web_asset copied to clipboard
Add field for setting the user agent
Servers like the osm tile servers require a user agent to be able to rate limit bots and apps
Thanks! I think it's a useful feature to have, but maybe warn if it's set on wasm because we can't implement it there?
@johanhelsing This should be doable on wasm. On the web-sys
Window
there is a method called fetch_with_str_and_init
. RequestInit
has a headers field where I am assuming the User-Agent
header can be specified.
https://github.com/rustwasm/wasm-bindgen/blob/4b6ef26f8a1dc1cd62329918dbe646cf9c142113/crates/web-sys/src/features/gen_Window.rs#L2991
I thought perhaps browsers didn't let you set that header... Have you tried it?
I thought perhaps browsers didn't let you set that header... Have you tried it?
@johanhelsing I hadn't considered that, but after doing a test with fetch
and XMLHttpRequest
respectively, Chrome based browsers are the outlier and they don't support setting this header and will just drop it if you specify it. But my tests showed It works on Firefox and Safari on iOS though.
User-Agent
was restricted historically, however its not classed as a forbidden header now according to the fetch spec.
https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name https://fetch.spec.whatwg.org/#forbidden-request-header
Chromium Bug: https://issues.chromium.org/issues/40450316
Not sure if its worth adding on WASM then, considering this.
Thanks for doing the digging!
Wasm could still be useful for people doing a webview-like thing. I'm fine not supporting it in this PR, but it should at least be big warning, both runtime and in the docs if you try to use it there.