Avoid creating a new HttpClient per HttpWebRequest in some cases
In .NET Core, HttpWebRequest is layered on top of HttpClient and HttpClientHandler. Due to the mismatch in APIs, the implementation creates a new HttpClient per HttpWebRequest, which is very inefficient. But those costs can be avoided in some circumstances. In particular, we can have a shared HttpClient configured with the same defaults that HttpWebRequest has; then as long as none of the settings on the HttpWebRequest have been changed to veer from the defaults, the shared HttpClient instance can be used rather than creating a new one.
Just curious, would/could this get impacted by https://github.com/dotnet/corefx/issues/11224?
Currently, the caching was implemented with the simplest possible strategy which caches and reuses the static single instance of HttpClient when the given HttpWebRequest parameters match to the ones of the cached instance. Moreover, caching is only allowed if all security and proxy related parameters are set to null or default values. Further, this can be improved by creating a pool of HttpClients matching to different combinations of HttpWebRequest parameters, and potentially permitting to cache some of security or proxy related settings as well.