FeedReader icon indicating copy to clipboard operation
FeedReader copied to clipboard

Bad usage of the HttpClient

Open ghost opened this issue 8 months ago • 0 comments

Your implementation of the usage from the HttpClient is bad.

Unfortunately, correct lifetime management of HttpClient is one of the biggest gotchas in .NET, MS really needs to fix it: it's unreasonable to expect people to understand concepts like socket-exhaustion and such when all they want to do is make a web-request every 15 minutes in a Windows Service, for example.

So a better solution is using a IHttpClientFactory to create the HttpClient for each single request. Maybe you can realize this with HttpClientFactory.CreateHttpClient.

This would be a better solution, but there are still a lot of issues with it:

  1. There is no way for me to set a UserClient (ApplicationName) for the HttpClient.
  2. There is no way for me to configure a Proxy server.
  3. There is no way for me to log HTTP requests.

To let me do all of this, it would be nice if you would implement a Callback function, how I can create the HttpClient by myself.

You could realize this, for example, with a static event in your Helpers.cs file. If you invoke this event before each HttpClient usage, I could create my own HttpClient every time fresh. And if I don't register to the event, you could use your static HttpClient furthermore.

This solution should be not a lot of work for you.

If you are interested, I would realize this and offer with a Pull Request to you.

What do you thing?

ghost avatar Oct 20 '23 02:10 ghost