Skip to content

Commit

Permalink
(GH-8) Accept null as proxy override
Browse files Browse the repository at this point in the history
This commit fixes null rejection as argument for
ProxyCache.Override method. It should be allowed because this
value represents empty proxy (according to MSDN Documentation).
  • Loading branch information
Cubix651 authored and ferventcoder committed Mar 1, 2017
1 parent 7e9da86 commit 26559a4
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/Core/Http/ProxyCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ProxyCache : IProxyCache
/// </summary>
private static readonly IWebProxy _originalSystemProxy = WebRequest.GetSystemWebProxy();
private IWebProxy _overrideProxy;
private bool _isProxyOverridden = false;

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

Expand Down Expand Up @@ -56,13 +57,14 @@ public static ProxyCache Instance

public IWebProxy GetProxy(Uri uri, bool bypassProxy)
{

if (bypassProxy) return null;

if (_overrideProxy != null)
if (_isProxyOverridden)
{
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 @@ -142,15 +144,20 @@ 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;
}
_overrideProxy = proxy;
_isProxyOverridden = true;

}

public void ClearOverriding()
{
_overrideProxy = null;
_isProxyOverridden = false;

}

private static WebProxy GetSystemProxy(Uri uri)
Expand Down

0 comments on commit 26559a4

Please sign in to comment.