diff options
author | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2009-07-23 03:29:10 +0400 |
---|---|---|
committer | Gonzalo Paniagua Javier <gonzalo.mono@gmail.com> | 2009-07-23 03:29:10 +0400 |
commit | 874ad36781ad7f0950d3c2a051beb478ee10b148 (patch) | |
tree | 08000c46540037a469e334d55d977f6c5f6b5d74 /mcs/class | |
parent | c9bf6e9a786ee8c32c9b860ad4ce5fcc9aa8389f (diff) |
Implement the 2.0 IsRestricted and add tests
svn path=/trunk/mcs/; revision=138472
Diffstat (limited to 'mcs/class')
-rw-r--r-- | mcs/class/System/System.Net/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/class/System/System.Net/WebHeaderCollection.cs | 24 | ||||
-rw-r--r-- | mcs/class/System/Test/System.Net/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs | 90 |
4 files changed, 119 insertions, 3 deletions
diff --git a/mcs/class/System/System.Net/ChangeLog b/mcs/class/System/System.Net/ChangeLog index 7aaa2be969a..86b391ca61d 100644 --- a/mcs/class/System/System.Net/ChangeLog +++ b/mcs/class/System/System.Net/ChangeLog @@ -1,5 +1,9 @@ 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 writes instead of throwing. Fixes bug #524049. diff --git a/mcs/class/System/System.Net/WebHeaderCollection.cs b/mcs/class/System/System.Net/WebHeaderCollection.cs index a210ab02f8d..f34248a02ea 100644 --- a/mcs/class/System/System.Net/WebHeaderCollection.cs +++ b/mcs/class/System/System.Net/WebHeaderCollection.cs @@ -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 diff --git a/mcs/class/System/Test/System.Net/ChangeLog b/mcs/class/System/Test/System.Net/ChangeLog index 2015be81b1b..b636565ed11 100644 --- a/mcs/class/System/Test/System.Net/ChangeLog +++ b/mcs/class/System/Test/System.Net/ChangeLog @@ -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 diff --git a/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs b/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs index 384ba0eaf3e..a840997db29 100644 --- a/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs +++ b/mcs/class/System/Test/System.Net/WebHeaderCollectionTest.cs @@ -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 } } + |