question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow HttpClient Headers configuration per request

See original GitHub issue

Description

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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ilightcommented, Sep 25, 2018

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.

0reactions
DavidStrickland0commented, May 16, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found