egui icon indicating copy to clipboard operation
egui copied to clipboard

Add a User-Agent header to HTTP image loader

Open mathiasyde opened this issue 1 year ago • 5 comments

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

mathiasyde avatar May 12 '24 23:05 mathiasyde

Sounds good - PRs welcome!

emilk avatar May 13 '24 10:05 emilk

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

mathiasyde avatar May 13 '24 13:05 mathiasyde

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 avatar May 13 '24 14:05 mathiasyde

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() :upside_down_face:

mathiasyde avatar May 13 '24 19:05 mathiasyde

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

emilk avatar May 14 '24 09:05 emilk