Allow HttpClient Headers configuration per request
See original GitHub issueDescription
In some cases, https://github.com/luberda-molinet/FFImageLoading/wiki/Authentication-Support does not suffice the needs for authentication. For example, you need to load images with authentication parameters that are different from time to time. This gets quite tricky when using a custom HttpClientHandler.
I’d suggest adding the option to configure the default Headers in the CachedImage.
Example:
var img = new CachedImage {
Source = new UriImageSource {
Uri = "https://secure.example.com/image.jpg"
},
Headers = {
Authorization = new AuthenticationHeaderValue("Basic", "dXNlcjpwYXNz")
}
};
Basic Information
- Version with issue: Up to current (v2.4.3.840)
- Last known good version: N/A
- Platform: All
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Modify request headers per request C# HttpClient PCL
Now I have a problem while writing a client library for a service. Some API calls need to have a specific header, some...
Read more >C# HttpClient - How to add request headers per request
This post describes how you can set headers on a HTTP request instead of setting it on the HttpClient and for all requests...
Read more >[API] Add per request headers override to HttpClient ...
The way to send custom per request headers with HttpClient is via SendAsync and adding them to the HttpRequestMessage .
Read more >C# - How to add request headers when using HttpClient
Add headers for all requests using HttpClient.DefaultRequestHeaders. Add headers per request using HttpRequestMessage.Headers + HttpClient.
Read more >HttpClient.DefaultRequestHeaders Property
The DefaultRequestHeaders property represents the headers that an app developer can set, not all of the headers that may eventually be sent with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just started using FFImageLoading for my Xamarin.iOS app and I’m stuck right here. Only few requests need to have Authorization headers but not all. Looking for a workaround at least.
So for those “Looking for a work around” as the Op points out a Custom HttpClientHandler will work its just painful. But its such a common issue because of the way MS created the HttpClient it crops up in almost every project. With an HttpClientHandler you can intercept the request just before it goes out on the wire, alter it however you want and then put it back onto the wire. In the SendAsync Method of the HttpClientHandler check the Request Body or Uri and add whatever header you need. You pass in anything you need (IE Credential sets) on the constructor of the Handler and then apply them based on whatever analysis you do inside the sendasync method. It works… its just painful and none intuitive.