Header names should be compared binary but not linguistic.
authorxplicit <svg@ngs.ru>
Tue, 10 Dec 2013 05:02:09 +0000 (12:02 +0700)
committerxplicit <svg@ngs.ru>
Tue, 10 Dec 2013 05:02:09 +0000 (12:02 +0700)
Moreover according to RFC2616 header names are subset of ASCII chars [0-127],
so culture-aware comparison is useless and eats too many processor time
(according to my benchmarks get an item from Hashtable with OrdinalIgnoreCase
comparers more than 20x times faster compared to Hashtable with InvariantCultureIgnoreCase
comparer)

mcs/class/System.Web/System.Web/HttpHeaderCollection.cs
mcs/class/System.Web/System.Web/HttpResponse.cs

index 6bc6917339bfedb7f961351a97ffc89c04257c18..b015d16ef6ec45ec185052ff0e17381add7103f1 100644 (file)
@@ -34,6 +34,10 @@ namespace System.Web
        {
                bool? headerCheckingEnabled;
 
+               public HttpHeaderCollection () : base (StringComparer.OrdinalIgnoreCase)
+               {
+               }
+
                bool HeaderCheckingEnabled {
                        get {
                                if (headerCheckingEnabled == null)
index ac432ab3da3b51044b1fe2f3ce0f4561c102d5e8..053d20c9c58b9baa0a741ee35ea327dbf1a9ae48 100644 (file)
@@ -510,27 +510,27 @@ namespace System.Web
                        if (headers_sent)
                                throw new HttpException ("Headers have been already sent");
 #if !TARGET_J2EE
-                       if (String.Compare (name, "content-length", true, Helpers.InvariantCulture) == 0){
+                       if (String.Compare (name, "content-length", StringComparison.OrdinalIgnoreCase) == 0){
                                content_length = (long) UInt64.Parse (value);
                                use_chunked = false;
                                return;
                        }
 #endif
 
-                       if (String.Compare (name, "content-type", true, Helpers.InvariantCulture) == 0){
+                       if (String.Compare (name, "content-type", StringComparison.OrdinalIgnoreCase) == 0){
                                ContentType = value;
                                return;
                        }
 
 #if !TARGET_J2EE
-                       if (String.Compare (name, "transfer-encoding", true, Helpers.InvariantCulture) == 0){
+                       if (String.Compare (name, "transfer-encoding", StringComparison.OrdinalIgnoreCase) == 0){
                                transfer_encoding = value;
                                use_chunked = false;
                                return;
                        }
 #endif
 
-                       if (String.Compare (name, "cache-control", true, Helpers.InvariantCulture) == 0){
+                       if (String.Compare (name, "cache-control", StringComparison.OrdinalIgnoreCase) == 0){
                                user_cache_control = value;
                                return;
                        }