I have anywhere from 10-150 long living class objects that call methods performing simple HTTPS API calls using HttpClient. Example of a PUT call:
This is how I change the HttpClientHandler
proxy without recreating the object.
public static void ChangeProxy(this HttpClientHandler handler, WebProxy newProxy)
{
if (handler.Proxy is WebProxy currentHandlerProxy)
{
currentHandlerProxy.Address = newProxy.Address;
currentHandlerProxy.Credentials = newProxy.Credentials;
}
else
{
handler.Proxy = newProxy;
}
}