[runtime] Replace pedump boehm dependency with sgen dependency
[mono.git] / mcs / class / System / System.Net / WebProxy.cs
index 6d718a117e2ad09ae5cfddec7a7ba2a13eccdfdd..365535a056bb4b561f1eb55aef21e100c4da2305 100644 (file)
 
 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
 
@@ -76,18 +79,18 @@ namespace System.Net
                {
                        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 ();
                }
@@ -99,11 +102,15 @@ namespace System.Net
                }
 
                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 ();
@@ -122,7 +129,14 @@ namespace System.Net
                        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 ()
                {
@@ -144,17 +158,36 @@ namespace System.Net
 
                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], 
@@ -180,19 +213,27 @@ namespace System.Net
                        }
                }
 
+               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]);
                }
@@ -202,11 +243,10 @@ namespace System.Net
                        if (address == null)
                                return null;
                                
-                       if (address.IndexOf ("://") == -1) 
+                       if (address.IndexOf ("://", StringComparison.Ordinal) == -1) 
                                address = "http://" + address;
 
                        return new Uri (address);
                }
        }
 }
-