NuGet.ProxyCache.IsSystemProxySet C# (CSharp) Method

IsSystemProxySet() private static method

Return true or false if connecting through a proxy server
private static IsSystemProxySet ( Uri uri ) : bool
uri System.Uri
return bool
        private static bool IsSystemProxySet(Uri uri)
        {
            // The reason for not calling the GetSystemProxy is because the object
            // that will be returned is no longer going to be the proxy that is set by the settings
            // on the users machine only the Address is going to be the same.
            // Not sure why the .NET team did not want to expose all of the useful settings like
            // ByPass list and other settings that we can't get because of it.
            // Anyway the reason why we need the DefaultWebProxy is to see if the uri that we are
            // getting the proxy for to should be bypassed or not. If it should be bypassed then
            // return that we don't need a proxy and we should try to connect directly.
            IWebProxy proxy = WebRequest.DefaultWebProxy;
            if (proxy != null)
            {
                Uri proxyAddress = new Uri(proxy.GetProxy(uri).AbsoluteUri);
                if (String.Equals(proxyAddress.AbsoluteUri, uri.AbsoluteUri))
                {
                    return false;
                }
                bool bypassUri = proxy.IsBypassed(uri);
                if (bypassUri)
                {
                    return false;
                }
                proxy = new WebProxy(proxyAddress);
            }

            return proxy != null;
        }
    }