Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field for setting the user agent #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

oli-obk
Copy link

@oli-obk oli-obk commented Nov 30, 2023

Servers like the osm tile servers require a user agent to be able to rate limit bots and apps

@johanhelsing
Copy link
Owner

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?

@danielfeather
Copy link

@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

@johanhelsing
Copy link
Owner

I thought perhaps browsers didn't let you set that header... Have you tried it?

@danielfeather
Copy link

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.

@johanhelsing
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants