using System;
using System.Collections;
+using System.Globalization;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
namespace System.Net
{
[Serializable]
- public class WebProxy : IWebProxy, ISerializable {
+ public class WebProxy : IWebProxy, ISerializable
+ {
Uri address;
bool bypassOnLocal;
ArrayList bypassList;
ICredentials credentials;
+ bool useDefaultCredentials;
// Constructors
{
this.address = address;
this.bypassOnLocal = bypassOnLocal;
- if (bypassList == null)
- bypassList = new string [] {};
- this.bypassList = new ArrayList (bypassList);
+ if (bypassList != null)
+ this.bypassList = new ArrayList (bypassList);
this.credentials = credentials;
CheckBypassList ();
}
protected WebProxy (SerializationInfo serializationInfo, StreamingContext streamingContext)
{
- this.address = (Uri) serializationInfo.GetValue ("address", typeof (Uri));
- this.bypassOnLocal = serializationInfo.GetBoolean ("bypassOnLocal");
- this.bypassList = (ArrayList) serializationInfo.GetValue ("bypassList", typeof (ArrayList));
+ this.address = (Uri) serializationInfo.GetValue ("_ProxyAddress", typeof (Uri));
+ this.bypassOnLocal = serializationInfo.GetBoolean ("_BypassOnLocal");
+ this.bypassList = (ArrayList) serializationInfo.GetValue ("_BypassList", typeof (ArrayList));
+ this.useDefaultCredentials = serializationInfo.GetBoolean ("_UseDefaultCredentials");
this.credentials = null;
CheckBypassList ();
}
}
public ArrayList BypassArrayList {
- get { return bypassList; }
+ get {
+ if (bypassList == null)
+ bypassList = new ArrayList ();
+ return bypassList;
+ }
}
public string [] BypassList {
- get { return (string []) bypassList.ToArray (typeof (string)); }
+ get { return (string []) BypassArrayList.ToArray (typeof (string)); }
set {
if (value == null)
throw new ArgumentNullException ();
set { credentials = value; }
}
+ [MonoTODO ("Does not affect Credentials, since CredentialCache.DefaultCredentials is not implemented.")]
+ public bool UseDefaultCredentials {
+ get { return useDefaultCredentials; }
+ set { useDefaultCredentials = value; }
+ }
+
// Methods
+ [Obsolete ("This method has been deprecated", false)]
[MonoTODO("Can we get this info under windows from the system?")]
public static WebProxy GetDefaultProxy ()
{
public bool IsBypassed (Uri host)
{
- if (address == null)
+ if (host == null)
+ throw new ArgumentNullException ("host");
+
+ if (host.IsLoopback && bypassOnLocal)
return true;
- if (bypassOnLocal && host.IsLoopback)
+ if (address == null)
return true;
- if (bypassOnLocal && host.Host.IndexOf ('.') == -1)
+ string server = host.Host;
+ if (bypassOnLocal && server.IndexOf ('.') == -1)
return true;
- try {
- string hostStr = host.Scheme + "://" + host.Authority;
+ // LAMESPEC
+ if (!bypassOnLocal) {
+ if (String.Compare (server, "localhost", true, CultureInfo.InvariantCulture) == 0)
+ return true;
+ if (String.Compare (server, "loopback", true, CultureInfo.InvariantCulture) == 0)
+ return true;
+
+ IPAddress addr = null;
+ if (IPAddress.TryParse (server, out addr) && IPAddress.IsLoopback (addr))
+ return true;
+ }
+
+ if (bypassList == null || bypassList.Count == 0)
+ return false;
+
+ try {
+ string hostStr = host.Scheme + "://" + host.Authority;
int i = 0;
for (; i < bypassList.Count; i++) {
Regex regex = new Regex ((string) bypassList [i],
}
}
+ protected virtual void GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)
+ {
+ serializationInfo.AddValue ("_BypassOnLocal", bypassOnLocal);
+ serializationInfo.AddValue ("_ProxyAddress", address);
+ serializationInfo.AddValue ("_BypassList", bypassList);
+ serializationInfo.AddValue ("_UseDefaultCredentials", UseDefaultCredentials);
+ }
+
void ISerializable.GetObjectData (SerializationInfo serializationInfo,
StreamingContext streamingContext)
{
- serializationInfo.AddValue ("bypassOnLocal", bypassOnLocal);
- serializationInfo.AddValue ("address", address);
- serializationInfo.AddValue ("bypassList", bypassList);
+ GetObjectData (serializationInfo, streamingContext);
}
// Private Methods
// this compiles the regular expressions, and will throw
// an exception when an invalid one is found.
void CheckBypassList ()
- {
+ {
+ if (bypassList == null)
+ return;
for (int i = 0; i < bypassList.Count; i++)
new Regex ((string) bypassList [i]);
}
if (address == null)
return null;
- if (address.IndexOf ("://") == -1)
+ if (address.IndexOf ("://", StringComparison.Ordinal) == -1)
address = "http://" + address;
return new Uri (address);
}
}
}
-