Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mcs / class / System / System.Net / WebRequest.cs
index b45bf2f54c00eb97ecc9590435da11c6e8984fda..bb1f13c06643604115e022fb60abccb4f73c4d48 100644 (file)
@@ -32,8 +32,12 @@ using System.Collections.Specialized;
 using System.Configuration;
 using System.IO;
 using System.Runtime.Serialization;
+using System.Globalization;
 #if NET_2_0
 using System.Net.Configuration;
+using System.Net.Security;
+using System.Net.Cache;
+using System.Security.Principal;
 #endif
 
 namespace System.Net 
@@ -42,6 +46,10 @@ namespace System.Net
        public abstract class WebRequest : MarshalByRefObject, ISerializable
        {
                static HybridDictionary prefixes = new HybridDictionary ();
+#if NET_2_0
+               static bool isDefaultWebProxySet;
+               static IWebProxy defaultWebProxy;
+#endif
                
                // Constructors
                
@@ -66,93 +74,155 @@ namespace System.Net
                
                protected WebRequest (SerializationInfo serializationInfo, StreamingContext streamingContext) 
                {
+#if ONLY_1_1
+                       throw GetMustImplement ();
+#endif
+               }
+
+               static Exception GetMustImplement ()
+               {
+                       return new NotImplementedException ("This method must be implemented in derived classes");
                }
                
                // Properties
+
+#if NET_2_0
+               private AuthenticationLevel authentication_level = AuthenticationLevel.MutualAuthRequested;
                
-               public virtual string ConnectionGroupName { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+               public AuthenticationLevel AuthenticationLevel
+               {
+                       get {
+                               return(authentication_level);
+                       }
+                       set {
+                               authentication_level = value;
+                       }
+               }
+
+               public virtual RequestCachePolicy CachePolicy
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                       }
+               }
+#endif
+               
+               public virtual string ConnectionGroupName {
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual long ContentLength { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual string ContentType { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual ICredentials Credentials { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
+               }
+
+#if NET_2_0
+               public static RequestCachePolicy DefaultCachePolicy
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
                }
+#endif
                
                public virtual WebHeaderCollection Headers { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
+#if NET_2_0
+               public TokenImpersonationLevel ImpersonationLevel {
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
+               }
+#endif
                public virtual string Method { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual bool PreAuthenticate { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual IWebProxy Proxy { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
                public virtual Uri RequestUri { 
-                       get { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
                }
                
                public virtual int Timeout { 
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
+                       get { throw GetMustImplement (); }
+                       set { throw GetMustImplement (); }
                }
                
 #if NET_2_0
-               volatile static IWebProxy proxy;
+               public virtual bool UseDefaultCredentials
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+                       set {
+                               throw GetMustImplement ();
+                       }
+               }
+               
+//             volatile static IWebProxy proxy;
                static readonly object lockobj = new object ();
                
                public static IWebProxy DefaultWebProxy {
                        get {
-                               lock (lockobj) {
-                                       if (proxy == null)
-                                               proxy = GetDefaultWebProxy ();
-                                       return proxy;
+                               if (!isDefaultWebProxySet) {
+                                       lock (lockobj) {
+                                               if (defaultWebProxy == null)
+                                                       defaultWebProxy = GetDefaultWebProxy ();
+                                       }
                                }
+                               return defaultWebProxy;
                        }
                        set {
-                               if (value == null)
-                                       throw new ArgumentNullException ("WebRequest.DefaultWebProxy",
-                                                       "null IWebProxy not allowed.");
-                               proxy = value;
+                               /* MS documentation states that a null value would cause an ArgumentNullException
+                                * but that's not the way it behaves:
+                                * https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=304724
+                                */
+                               defaultWebProxy = value;
+                               isDefaultWebProxySet = true;
                        }
                }
                
                [MonoTODO("Needs to respect Module, Proxy.AutoDetect, and Proxy.ScriptLocation config settings")]
                static IWebProxy GetDefaultWebProxy ()
                {
-                       WebProxy p;
+                       WebProxy p = null;
                        
 #if CONFIGURATION_DEP
-                       System.Configuration.Configuration config = ConfigurationManager.OpenMachineConfiguration ();
-                       DefaultProxySection sec = config.GetSection ("system.net/defaultProxy") as DefaultProxySection;
+                       DefaultProxySection sec = ConfigurationManager.GetSection ("system.net/defaultProxy") as DefaultProxySection;
                        if (sec == null)
-                               return GlobalProxySelection.GetEmptyWebProxy ();
+                               return GetSystemWebProxy ();
                        
                        ProxyElement pe = sec.Proxy;
                        
-                       if ((pe.UseSystemDefault == ProxyElement.UseSystemDefaultValues.True) && (pe.ProxyAddress == null))
+                       if ((pe.UseSystemDefault != ProxyElement.UseSystemDefaultValues.False) && (pe.ProxyAddress == null))
                                p = (WebProxy) GetSystemWebProxy ();
                        else
                                p = new WebProxy ();
@@ -164,24 +234,24 @@ namespace System.Net
                                p.BypassProxyOnLocal = (pe.BypassOnLocal == ProxyElement.BypassOnLocalValues.True);
 #endif
                        return p;
-               }               
+               }
 #endif
 
                // Methods
                
                public virtual void Abort()
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
                public virtual IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) 
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
                public virtual IAsyncResult BeginGetResponse (AsyncCallback callback, object state)
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
 
                public static WebRequest Create (string requestUriString) 
@@ -207,22 +277,22 @@ namespace System.Net
 
                public virtual Stream EndGetRequestStream (IAsyncResult asyncResult)
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
                public virtual WebResponse EndGetResponse (IAsyncResult asyncResult)
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
                public virtual Stream GetRequestStream()
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
                public virtual WebResponse GetResponse()
                {
-                       throw new NotImplementedException ();
+                       throw GetMustImplement ();
                }
                
 #if NET_2_0
@@ -240,21 +310,30 @@ namespace System.Net
                }
 #endif
 
-               void ISerializable.GetObjectData (SerializationInfo serializationInfo,
+               void ISerializable.GetObjectData
+               (SerializationInfo serializationInfo,
                                                  StreamingContext streamingContext)
                {
                        throw new NotSupportedException ();
                }
 
+
+#if NET_2_0
+               protected virtual void GetObjectData (SerializationInfo serializationInfo, StreamingContext streamingContext)
+               {
+                       throw GetMustImplement ();
+               }
+#endif
+
                public static bool RegisterPrefix (string prefix, IWebRequestCreate creator)
                {
                        if (prefix == null)
-                               throw new ArgumentNullException("prefix");
+                               throw new ArgumentNullException ("prefix");
                        if (creator == null)
-                               throw new ArgumentNullException("creator");                     
+                               throw new ArgumentNullException ("creator");
                        
                        lock (prefixes.SyncRoot) {
-                               string lowerCasePrefix = prefix.ToLower ();
+                               string lowerCasePrefix = prefix.ToLower (CultureInfo.InvariantCulture);
                                if (prefixes.Contains (lowerCasePrefix))
                                        return false;
                                prefixes.Add (lowerCasePrefix, creator);
@@ -267,7 +346,7 @@ namespace System.Net
                        int longestPrefix = -1;
                        IWebRequestCreate creator = null;
 
-                       prefix = prefix.ToLower ();
+                       prefix = prefix.ToLower (CultureInfo.InvariantCulture);
 
                        IDictionaryEnumerator e = prefixes.GetEnumerator ();
                        while (e.MoveNext ()) {
@@ -277,7 +356,7 @@ namespace System.Net
                                        continue;
                                
                                if (!prefix.StartsWith (key))
-                                       continue;                                       
+                                       continue;
                                        
                                longestPrefix = key.Length;
                                creator = (IWebRequestCreate) e.Value;