Enable the System build for monodroid
[mono.git] / mcs / class / System / System.Net / WebRequest.cs
index b483c1477da1ce5b2a6e3ece16c4e6509f28f877..533dd17f7a6475f2cca1ddd73b8cddf81724bd22 100644 (file)
@@ -40,22 +40,45 @@ using System.Net.Cache;
 using System.Security.Principal;
 #endif
 
+#if NET_2_1
+using ConfigurationException = System.ArgumentException;
+
+namespace System.Net.Configuration {
+       class Dummy {}
+}
+#endif
+
 namespace System.Net 
 {
+#if MOONLIGHT
+       internal abstract class WebRequest : ISerializable {
+#else
        [Serializable]
-       public abstract class WebRequest : MarshalByRefObject, ISerializable
-       {
+       public abstract class WebRequest : MarshalByRefObject, ISerializable {
+#endif
                static HybridDictionary prefixes = new HybridDictionary ();
 #if NET_2_0
                static bool isDefaultWebProxySet;
                static IWebProxy defaultWebProxy;
+               static RequestCachePolicy defaultCachePolicy;
 #endif
                
                // Constructors
-#if !NET_2_1
+               
                static WebRequest ()
                {
-#if NET_2_0 && CONFIGURATION_DEP
+#if NET_2_1
+                       AddPrefix ("http", typeof (HttpRequestCreator));
+                       AddPrefix ("https", typeof (HttpRequestCreator));
+       #if MOBILE
+                       AddPrefix ("file", typeof (FileWebRequestCreator));
+                       AddPrefix ("ftp", typeof (FtpRequestCreator));
+       #endif
+#else
+       #if NET_2_0
+                       defaultCachePolicy = new HttpRequestCachePolicy (HttpRequestCacheLevel.NoCacheNoStore);
+       #endif
+       #if NET_2_0 && CONFIGURATION_DEP
                        object cfg = ConfigurationManager.GetSection ("system.net/webRequestModules");
                        WebRequestModulesSection s = cfg as WebRequestModulesSection;
                        if (s != null) {
@@ -64,10 +87,10 @@ namespace System.Net
                                        AddPrefix (el.Prefix, el.Type);
                                return;
                        }
-#endif
+       #endif
                        ConfigurationSettings.GetConfig ("system.net/webRequestModules");
-               }
 #endif
+               }
                
                protected WebRequest () 
                {
@@ -100,13 +123,11 @@ namespace System.Net
                        }
                }
 
+               [MonoTODO ("Implement the caching system. Currently always returns a policy with the NoCacheNoStore level")]
                public virtual RequestCachePolicy CachePolicy
                {
-                       get {
-                               throw GetMustImplement ();
-                       }
+                       get { return DefaultCachePolicy; }
                        set {
-                               throw GetMustImplement ();
                        }
                }
 #endif
@@ -134,9 +155,7 @@ namespace System.Net
 #if NET_2_0
                public static RequestCachePolicy DefaultCachePolicy
                {
-                       get {
-                               throw GetMustImplement ();
-                       }
+                       get { return defaultCachePolicy; }
                        set {
                                throw GetMustImplement ();
                        }
@@ -148,7 +167,7 @@ namespace System.Net
                        set { throw GetMustImplement (); }
                }
                
-#if NET_2_0
+#if NET_2_0 && !MOONLIGHT
                public TokenImpersonationLevel ImpersonationLevel {
                        get { throw GetMustImplement (); }
                        set { throw GetMustImplement (); }
@@ -189,7 +208,7 @@ namespace System.Net
                        }
                }
                
-               volatile static IWebProxy proxy;
+//             volatile static IWebProxy proxy;
                static readonly object lockobj = new object ();
                
                public static IWebProxy DefaultWebProxy {
@@ -302,11 +321,28 @@ namespace System.Net
                public static IWebProxy GetSystemWebProxy ()
                {
                        string address = Environment.GetEnvironmentVariable ("http_proxy");
+                       if (address == null)
+                               address = Environment.GetEnvironmentVariable ("HTTP_PROXY");
+
                        if (address != null) {
                                try {
-                                       WebProxy p = new WebProxy (address);
-                                       return p;
-                               } catch (UriFormatException) {}
+                                       if (!address.StartsWith ("http://"))
+                                               address = "http://" + address;
+                                       Uri uri = new Uri (address);
+                                       IPAddress ip;
+                                       if (IPAddress.TryParse (uri.Host, out ip)) {
+                                               if (IPAddress.Any.Equals (ip)) {
+                                                       UriBuilder builder = new UriBuilder (uri);
+                                                       builder.Host = "127.0.0.1";
+                                                       uri = builder.Uri;
+                                               } else if (IPAddress.IPv6Any.Equals (ip)) {
+                                                       UriBuilder builder = new UriBuilder (uri);
+                                                       builder.Host = "[::1]";
+                                                       uri = builder.Uri;
+                                               }
+                                       }
+                                       return new WebProxy (uri);
+                               } catch (UriFormatException) { }
                        }
                        return new WebProxy ();
                }
@@ -384,11 +420,7 @@ namespace System.Net
                {
                        Type type = Type.GetType (typeName);
                        if (type == null)
-#if !NET_2_1
                                throw new ConfigurationException (String.Format ("Type {0} not found", typeName));
-#else
-                               throw new Exception (String.Format ("Type {0} not found", typeName));
-#endif
                        AddPrefix (prefix, type);
                }