Open OliverBrown-Next opened 2 weeks ago
I saw 2 closed PRs when with this feature, would really appreciate to hear today's team's vision on this matter.
Bringing some thoughts:
Lyrics: For me this issue became an obvious problem for me when I got app to build where I had like 50% of images not loading, URLs were provided by third-party API. The cause was found to be that those URLs were coming from wiki that required UserAgent to be specified in client headers.
Created some example code for the discussion.
I used <PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.4" />
to add retry policy to image source.
https://github.com/taublast/maui/commit/4e4bd82c66022815d054064f71aeb318a513a2c9
Some tests:
One of the tests demonstrate how one could customize the client, we allow access to builder too:
This extension method is intended to be public.
To marry Glide with this, would think of providing a platform-conditional delegate code allowing to customize Glide builder in a same way we could allow with the IHttpCLientBuilder.
Customizing Glide loader example: https://github.com/taublast/maui/commit/5c1736dcd55b52eda701e0fd91a5c96a79b68460
Anyway we all need more thoughts and opinions from the team.
Description
Provide a way to customize the
HttpClient
(or possible theHttpClientHandler
) used onUIrImageSource
here: https://github.com/dotnet/maui/blob/abada83230d6ffb6f78af0b510b8ea3fcba1b863/src/Controls/src/Core/UriImageSource.cs#L117Public API Changes
I'm not sure of the best API shape.
Unsealing
UriImageSource
and changingDownloadStreamAsync
to beprotected virtual
would be one solution.Getting
HttpClient
from theIServiceCollection
would be a bigger change (or changing to useIHttpClientFactory
).Intended Use-Case
My main requirement is the ability to add custom headers when using HTTP sourced images.