New tests.
[mono.git] / mcs / class / System.Net / System.Net / HttpWebRequest_2_1.cs
index 33626da8af513d811bb764a774a5325473d625c1..e2fccc637c47b6d8beebe2548834221c022baadf 100644 (file)
@@ -5,7 +5,7 @@
 //     Atsushi Enomoto  <atsushi@ximian.com>
 //  Jb Evain  <jbevain@novell.com>
 //
-// Copyright (C) 2007, 2009 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2007, 2009-2010 Novell, Inc (http://www.novell.com)
 //
 
 //
@@ -37,10 +37,13 @@ namespace System.Net {
 
        // note: the NotImplementedException are needed to match MS implementation
 
+       // note: MS documents a lot of thing for this type but, in truth, all happens
+       // in a type that derive from HttpWebRequest. In Moonlight case this is either
+       // * BrowserHttpWebRequest (browser stack) located in System.Windows.Browser.dll; or
+       // * System.Net.Browser.ClientHttpWebRequest (client stack) located in System.Windows.dll
+
        public abstract class HttpWebRequest : WebRequest {
 
-               private string accept;
-               private string content_type;
                private WebHeaderCollection headers;
 
                protected HttpWebRequest ()
@@ -48,13 +51,9 @@ namespace System.Net {
                }
 
                public string Accept {
-                       get { return accept; }
-                       set {
-                               if (String.IsNullOrEmpty (value))
-                                       accept = null;
-                               else
-                                       accept = value;
-                       }
+                       get { return Headers [HttpRequestHeader.Accept]; }
+                       // this header cannot be set directly inside the collection (hence the helper)
+                       set { Headers.SetHeader ("accept", value); }
                }
 
                public virtual bool AllowReadStreamBuffering {
@@ -62,14 +61,16 @@ namespace System.Net {
                        set { throw NotImplemented (); }
                }
 
+               // new in SL4 RC
+               public virtual bool AllowWriteStreamBuffering {
+                       get { throw NotImplemented (); }
+                       set { throw NotImplemented (); }
+               }
+
                public override string ContentType {
-                       get { return content_type; }
-                       set {
-                               if (String.IsNullOrEmpty (value))
-                                       content_type = null;
-                               else
-                                       content_type = value;
-                       }
+                       get { return Headers [HttpRequestHeader.ContentType]; }
+                       // this header cannot be set directly inside the collection (hence the helper)
+                       set { Headers.SetHeader ("content-type", value); }
                }
 
                public virtual bool HaveResponse {
@@ -79,16 +80,30 @@ namespace System.Net {
                public override WebHeaderCollection Headers {
                        get {
                                if (headers == null)
-                                       headers = new WebHeaderCollection ();
+                                       headers = new WebHeaderCollection (true);
                                return headers;
                        }
                        set {
-                               if (value == null)
-                                       throw new NullReferenceException ();
-                               headers = value;
+                               // note: this is not a field assignment but a copy (see unit tests)
+                               // make sure everything we're supplied is valid...
+                               string[] keys = value.AllKeys;
+                               foreach (string header in keys) {
+                                       // anything bad will throw
+                                       WebHeaderCollection.ValidateHeader (header);
+                               }
+                               // ... before making those values our own
+                               Headers.headers.Clear ();
+                               foreach (string header in keys) {
+                                       headers [header] = value [header];
+                               }
                        }
                }
 
+               public virtual CookieContainer CookieContainer {
+                       get { throw NotImplemented (); }
+                       set { throw NotImplemented (); }
+               }
+
                public override string Method {
                        get { throw NotImplemented (); }
                        set { throw NotImplemented (); }
@@ -98,6 +113,10 @@ namespace System.Net {
                        get { throw NotImplemented (); }
                }
 
+               // new in SL4 RC
+               public virtual bool SupportsCookieContainer {
+                       get { return false; }
+               }
 
                public override void Abort ()
                {