Implement the 2.0 IsRestricted and add tests
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 22 Jul 2009 23:29:10 +0000 (23:29 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Wed, 22 Jul 2009 23:29:10 +0000 (23:29 -0000)
svn path=/trunk/mcs/; revision=138472

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/WebHeaderCollection.cs
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs

index 7aaa2be969aa0216e745d7731a202b5580f242c4..86b391ca61d64f0e73f7bb2d053c08e3b35ee7fc 100644 (file)
@@ -1,3 +1,7 @@
+2009-07-22 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * WebHeaderCollection.cs: implemente the 2.0 IsRestricted().
+
 2009-07-22 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * WebConnectionStream.cs: when sending a 0-length POST, ignore further
index a210ab02f8df1867a1cb847365b11300bec14d7b..f34248a02ea9dd693ed345b93b70b6191cb87de3 100644 (file)
@@ -33,6 +33,9 @@
 
 using System;
 using System.Collections;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
 using System.Collections.Specialized;
 using System.Runtime.InteropServices;
 using System.Runtime.Serialization;
@@ -48,6 +51,9 @@ namespace System.Net
        {
                private static readonly Hashtable restricted;
                private static readonly Hashtable multiValue;
+#if NET_2_0
+               static readonly Dictionary<string, bool> restricted_response;
+#endif
                private bool internallyCreated = false;
                
                // Static Initializer
@@ -71,7 +77,15 @@ namespace System.Net
                        restricted.Add ("referer", true);
                        restricted.Add ("transfer-encoding", true);
                        restricted.Add ("user-agent", true);                    
-                       
+                       restricted.Add ("proxy-connection", true);                      
+
+                       //
+#if NET_2_0
+                       restricted_response = new Dictionary<string, bool> (StringComparer.InvariantCultureIgnoreCase);
+                       restricted_response.Add ("Content-Length", true);
+                       restricted_response.Add ("Transfer-Encoding", true);
+                       restricted_response.Add ("WWW-Authenticate", true);
+#endif
                        // see par 14 of RFC 2068 to see which header names
                        // accept multiple values each separated by a comma
                        multiValue = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
@@ -247,10 +261,14 @@ namespace System.Net
                }
 
 #if NET_2_0
-               [MonoNotSupported("")]
                public static bool IsRestricted (string headerName, bool response)
                {
-                       throw new NotImplementedException ();
+                       if (String.IsNullOrEmpty (headerName))
+                               throw new ArgumentNullException ("headerName");
+
+                       if (response)
+                               return restricted_response.ContainsKey (headerName);
+                       return restricted.ContainsKey (headerName);
                }
 #endif
 
index 2015be81b1b15e3ad7d91d59471dcdca0974fdbe..b636565ed11cb3033a4f900fa237abe07e921a79 100644 (file)
@@ -1,3 +1,7 @@
+2009-07-22 Gonzalo Paniagua Javier <gonzalo@novell.com>
+
+       * WebHeaderCollectionTest.cs: test for 2.0 IsRestricted().
+
 2009-07-09 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * HttpWebRequestTest.cs: use different ports for different tests since
index 384ba0eaf3e01e13eacee74ea42959b519c989fc..a840997db29cf6766a7ca575011dd9df9b72481d 100644 (file)
@@ -5,6 +5,7 @@
 //   Lawrence Pit (loz@cable.a2000.nl)
 //   Martin Willemoes Hansen (mwh@sysrq.dk)
 //   Gert Driesen (drieseng@users.sourceforge.net)
+//   Gonzalo Paniagua Javier (gonzalo@novell.com)
 //
 // (C) 2003 Martin Willemoes Hansen
 //
@@ -375,5 +376,94 @@ namespace MonoTests.System.Net
                        0x74, 0x74, 0x61, 0x63, 0x68, 0x0b
 #endif
                };
+
+#if NET_2_0
+               static string [] request_headers = new string [] {
+                       "Accept", "Accept-Charset", "Accept-Encoding", "Accept-Language", "Accept-Ranges", "Authorization", 
+                       "Cache-Control", "Connection", "Cookie", "Content-Length", "Content-Type", "Date", 
+                       "Expect", "From", "Host", "If-Match", "If-Modified-Since", "If-None-Match", 
+                       "If-Range", "If-Unmodified-Since", "Max-Forwards", "Pragma", "Proxy-Authorization", 
+                       "Range", "Referer", "TE", "Upgrade", "User-Agent", "Via", "Warn" };
+
+               static string [] response_headers = new string [] {
+                       "Accept-Ranges", "Age", "Allow", "Cache-Control", "Content-Encoding", "Content-Language", 
+                       "Content-Length", "Content-Location", "Content-Disposition", "Content-MD5", "Content-Range", 
+                       "Content-Type", "Date", "ETag", "Expires", "Last-Modified", "Location", "Pragma", 
+                       "Proxy-Authenticate", "Retry-After", "Server", "Set-Cookie", "Trailer", 
+                       "Transfer-Encoding", "Vary", "Via", "Warn", "WWW-Authenticate" };
+
+               static string [] restricted_request_request = new string [] {
+                       "Accept", "Connection", "Content-Length", "Content-Type", "Date",
+                       "Expect", "Host", "If-Modified-Since", "Range", "Referer",
+                       "User-Agent" };
+               static string [] restricted_response_request = new string [] {
+                       "Content-Length", "Content-Type", "Date", "Transfer-Encoding" };
+
+               static string [] restricted_request_response = new string [] {
+                        "Content-Length" };
+               static string [] restricted_response_response = new string [] {
+                        "Content-Length", "Transfer-Encoding", "WWW-Authenticate" };
+
+               [Test]
+               public void IsRestricted_2_0_RequestRequest ()
+               {
+                       int count = 0;
+                       foreach (string str in request_headers) {
+                               if (WebHeaderCollection.IsRestricted (str, false)) {
+                                       Assert.IsTrue (Array.IndexOf (restricted_request_request, str) != -1, "restricted " + str);
+                                       count++;
+                               } else {
+                                       Assert.IsTrue (Array.IndexOf (restricted_request_request, str) == -1, str);
+                               }
+                       }
+                       Assert.IsTrue (count == restricted_request_request.Length, "req-req length");
+               }
+
+               [Test]
+               public void IsRestricted_2_0_ResponseRequest ()
+               {
+                       int count = 0;
+                       foreach (string str in response_headers) {
+                               if (WebHeaderCollection.IsRestricted (str, false)) {
+                                       Assert.IsTrue (Array.IndexOf (restricted_response_request, str) != -1, "restricted " + str);
+                                       count++;
+                               } else {
+                                       Assert.IsTrue (Array.IndexOf (restricted_response_request, str) == -1, str);
+                               }
+                       }
+                       Assert.IsTrue (count == restricted_response_request.Length, "length");
+               }
+
+               [Test]
+               public void IsRestricted_2_0_RequestResponse ()
+               {
+                       int count = 0;
+                       foreach (string str in request_headers) {
+                               if (WebHeaderCollection.IsRestricted (str, true)) {
+                                       Assert.IsTrue (Array.IndexOf (restricted_request_response, str) != -1, "restricted " + str);
+                                       count++;
+                               } else {
+                                       Assert.IsTrue (Array.IndexOf (restricted_request_response, str) == -1, str);
+                               }
+                       }
+                       Assert.IsTrue (count == restricted_request_response.Length, "length");
+               }
+
+               [Test]
+               public void IsRestricted_2_0_ResponseResponse ()
+               {
+                       int count = 0;
+                       foreach (string str in response_headers) {
+                               if (WebHeaderCollection.IsRestricted (str, true)) {
+                                       Assert.IsTrue (Array.IndexOf (restricted_response_response, str) != -1, "restricted " + str);
+                                       count++;
+                               } else {
+                                       Assert.IsTrue (Array.IndexOf (restricted_response_response, str) == -1, str);
+                               }
+                       }
+                       Assert.IsTrue (count == restricted_response_response.Length, "length");
+               }
+#endif
        }
 }
+