/// <summary>Indicates whether to use the proxy server for the specified host.</summary>
/// <returns>true if the proxy server should not be used for <paramref name="host" />; otherwise, false.</returns>
/// <param name="host">The <see cref="T:System.Uri" /> instance of the host to check for proxy use. </param>
public bool IsBypassed(System.Uri host)
{
if (host == null)
{
throw new ArgumentNullException("host");
}
if (host.IsLoopback && this.bypassOnLocal)
{
return(true);
}
if (this.address == null)
{
return(true);
}
string host2 = host.Host;
if (this.bypassOnLocal && host2.IndexOf('.') == -1)
{
return(true);
}
if (!this.bypassOnLocal)
{
if (string.Compare(host2, "localhost", true, CultureInfo.InvariantCulture) == 0)
{
return(true);
}
if (string.Compare(host2, "loopback", true, CultureInfo.InvariantCulture) == 0)
{
return(true);
}
IPAddress addr = null;
if (IPAddress.TryParse(host2, out addr) && IPAddress.IsLoopback(addr))
{
return(true);
}
}
if (this.bypassList == null || this.bypassList.Count == 0)
{
return(false);
}
bool result;
try
{
string input = host.Scheme + "://" + host.Authority;
int i;
for (i = 0; i < this.bypassList.Count; i++)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex((string)this.bypassList[i], System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Singleline);
if (regex.IsMatch(input))
{
break;
}
}
if (i == this.bypassList.Count)
{
result = false;
}
else
{
while (i < this.bypassList.Count)
{
new System.Text.RegularExpressions.Regex((string)this.bypassList[i]);
i++;
}
result = true;
}
}
catch (ArgumentException)
{
result = false;
}
return(result);
}