public WebProxy GetWebProxy()
{
const string httpPrefix = "http://";
WebProxy proxy = null;
if (!string.IsNullOrEmpty(ProxyHost) && ProxyPort > 0)
{
// WebProxy constructor adds the http:// prefix, but doesn't
// account for cases where it's already present which leads to
// malformed addresses
var host = ProxyHost.StartsWith(httpPrefix, StringComparison.OrdinalIgnoreCase)
? ProxyHost.Substring(httpPrefix.Length)
: ProxyHost;
proxy = new WebProxy(host, ProxyPort);
if (ProxyCredentials != null)
{
proxy.Credentials = ProxyCredentials;
}
if (ProxyBypassList != null)
{
proxy.BypassList = ProxyBypassList.ToArray();
}
proxy.BypassProxyOnLocal = ProxyBypassOnLocal;
}
return proxy;
}