ComputerGhost / FaviconFetcher

Scan a webpage for favicons, or just easily download the one you want.
MIT License
5 stars 3 forks source link

Add HttpClient to resolve deprecation of WebRequest #26

Open kiddailey opened 5 months ago

kiddailey commented 5 months ago

This pull request partially resolves issue #16 and adds support for the use of HttpClient. Please note that this is based on the branch for PR #25 which implements async support, so those changes are included as well.

Given the comment regarding maintaining the shared caching feature, I'm hopeful that this is a good solution as it simply builds upon the existing ISource interface and retains the use of WebRequest by default.

In summary:

Notes:

This obviously means that the caller must specify the source explicitly if they want to use HttpClient. Technically this is better regardless because according to Microsoft, HttpClient should have an extended life and not be constantly disposed. This somewhat encourages the caller to do so. e.g.:

var source = new HttpClientSource();
var fetcher = new Fetcher(source); // Uses HttpClient

If no source is specified, HttpSource is used, which is the deprecated WebRequest and is the same behavior as exists, e.g.:

var fetcher = new Fetcher(); // Uses WebRequest

I'll add documentation for all this to the readme as well when I can.

NOTE: I have a consolidated branch containing the SVG, Async and HttpClient pull requests into one if preferred. Since each PR is based off of the mainline, it does take a little work to combine them. Let me know

kiddailey commented 5 months ago

Discovered while testing on Android that I forgot to remove "any" encodings to be accepted in the request headers. Found this when some server response encodings were encoded with Brotli and causing things to fail. Due to NET Framework 2, we can only use Deflate and GZIP, so I limited it to those and removed the weights.

Interestingly enough, everything worked fine on iOS and Windows. Only Android was affected. Lots of guesses, but no solid idea why exactly. Weird.