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 a User-Agent header to HTTP image loader #4491

Open
MathiasYde opened this issue May 12, 2024 · 5 comments
Open

Add a User-Agent header to HTTP image loader #4491

MathiasYde opened this issue May 12, 2024 · 5 comments

Comments

@MathiasYde
Copy link

Is your feature request related to a problem? Please describe.

I'm trying to make an egui program that shows images loaded from an CDN, but it requires that the request has a user agent as a header.

Describe the solution you'd like

Either hardcore the user agent header into the code handling HTTP image loading or add a way to allow passing in a custom user agent

Describe alternatives you've considered

Loading the image using reqwest as bytes and use ImageSource::Bytes in Image

Additional context

@emilk
Copy link
Owner

emilk commented May 13, 2024

Sounds good - PRs welcome!

@MathiasYde
Copy link
Author

Are we going for a hard coded user agent or a configurable one? I could take a crack at it

@MathiasYde
Copy link
Author

I've been looking through the code a bit and found out that egui-extras uses ehttp for the http ImageLoader which has hardcoded headers of just ("Accept", "*/*")

Do you want to simply pass the headers into ehttp::Request::get function, a builder pattern? (ehttp::Request::get("http://..").with_headers(..).build()) or perhaps something else?

@MathiasYde
Copy link
Author

So a few hours of debugging and I found out that the URL I use to fetch images has unescaped qoutes ("\"https://..\"") which caused images to fail due to calling to_string() directly on serde_json::Value instead of something like as_str().unwrap_or("null").to_string() 🙃

@emilk
Copy link
Owner

emilk commented May 14, 2024

A hard-coded User-Agent: egui is a good start, but adding some way of changing it for EhttpLoader should be fairly easy.

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

No branches or pull requests

2 participants