public IWebProxy GetProxy(Uri uri)
{
// Check if the user has configured proxy details in settings or in the environment.
WebProxy configuredProxy = GetUserConfiguredProxy();
if (configuredProxy != null)
{
// If a proxy was cached, it means the stored credentials are incorrect. Use the cached one in this case.
WebProxy actualProxy;
if (_cache.TryGetValue(configuredProxy.Address, out actualProxy))
{
return actualProxy;
}
return configuredProxy;
}
if (!IsSystemProxySet(uri))
{
return null;
}
WebProxy systemProxy = GetSystemProxy(uri);
WebProxy effectiveProxy;
// See if we have a proxy instance cached for this proxy address
if (_cache.TryGetValue(systemProxy.Address, out effectiveProxy))
{
return effectiveProxy;
}
return systemProxy;
}