Skip to content

Commit

Permalink
GH-243) Allow explicit proxy override
Browse files Browse the repository at this point in the history
Allow passing a specific proxy into the proxy cache that is used no
matter what.
  • Loading branch information
ferventcoder committed Jan 20, 2016
1 parent 17ec714 commit 4b206ed
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Core/Http/ProxyCache.cs
Expand Up @@ -18,6 +18,7 @@ public class ProxyCache : IProxyCache
/// settings.
/// </summary>
private static readonly IWebProxy _originalSystemProxy = WebRequest.GetSystemWebProxy();
private IWebProxy _overrideProxy;

private readonly ConcurrentDictionary<Uri, WebProxy> _cache = new ConcurrentDictionary<Uri, WebProxy>();

Expand Down Expand Up @@ -55,6 +56,11 @@ public static ProxyCache Instance

public IWebProxy GetProxy(Uri uri)
{
if (_overrideProxy != null)
{
return _overrideProxy;
}

#if !BOOTSTRAPPER
// Check if the user has configured proxy details in settings or in the environment.
WebProxy configuredProxy = GetUserConfiguredProxy();
Expand Down Expand Up @@ -134,6 +140,15 @@ public void Add(IWebProxy proxy)
{
_cache.TryAdd(webProxy.Address, webProxy);
}
}

public void Override(IWebProxy proxy)
{
var webProxy = proxy as WebProxy;
if (webProxy != null)
{
_overrideProxy = webProxy;
}
}

private static WebProxy GetSystemProxy(Uri uri)
Expand Down

0 comments on commit 4b206ed

Please sign in to comment.