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

Provide a way to customize the HttpClient on UriImageSource #22057

Open
OliverBrown-Next opened this issue Apr 25, 2024 · 2 comments
Open

Provide a way to customize the HttpClient on UriImageSource #22057

OliverBrown-Next opened this issue Apr 25, 2024 · 2 comments

Comments

@OliverBrown-Next
Copy link

Description

Provide a way to customize the HttpClient (or possible the HttpClientHandler) used on UIrImageSource here:

using var client = new HttpClient();

Public API Changes

I'm not sure of the best API shape.

Unsealing UriImageSource and changing DownloadStreamAsync to be protected virtual would be one solution.

Getting HttpClient from the IServiceCollection would be a bigger change (or changing to use IHttpClientFactory).

Intended Use-Case

My main requirement is the ability to add custom headers when using HTTP sourced images.

@PureWeen
Copy link
Member

Related #10995

@Eilon Eilon added the area-image Image loading, sources, caching label Apr 30, 2024
@taublast
Copy link
Contributor

taublast commented May 3, 2024

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:

  • A real-world serious app would (personal bet and exp) include http extensions nuget to use httpfactory for intensive API calls. Not to include it targeting light demo app cases is a debatable choice for me.
  • Platform implementations like Android Glide should not limit the shared code to become more robust and modern, but should adapt to it. At the same time we can just omit http extensions for Android and think of a way to provide a fancy Glide builder customization method.

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.

taublast@4e4bd82

Some tests:

image

One of the tests demonstrate how one could customize the client, we allow access to builder too:

image

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: taublast@5c1736d

Anyway we all need more thoughts and opinions from the team.

@Eilon Eilon added area-controls-image and removed area-image Image loading, sources, caching labels May 10, 2024
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

5 participants