]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Use case-insensitive comparison for HTTP header names in *_header_access
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 16 May 2013 21:00:29 +0000 (15:00 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 16 May 2013 21:00:29 +0000 (15:00 -0600)
and *_header_replace directives.

src/HttpHeaderTools.h

index dafa78734af8d1708ac61758f4bfd813e61dd371..2a80986c1233a1bcfccd88b2a72fe31ea8187bc1 100644 (file)
@@ -5,6 +5,9 @@
 #include "HttpHeader.h"
 #include "typedefs.h"
 
+#if HAVE_FUNCTIONAL
+#include <functional>
+#endif
 #if HAVE_LIST
 #include <list>
 #endif
@@ -14,6 +17,9 @@
 #if HAVE_STRING
 #include <string>
 #endif
+#if HAVE_STRINGS_H
+#include <strings.h>
+#endif
 
 class acl_access;
 class ACLList;
@@ -56,8 +62,17 @@ public:
     void dumpReplacement(StoreEntry *entry, const char *optionName) const;
 
 private:
+    /// Case-insensitive std::string "less than" comparison functor.
+    /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
+    class NoCaseLessThan: public std::binary_function<std::string, std::string, bool> {
+    public:
+        bool operator()(const std::string &lhs, const std::string &rhs) const {
+            return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
+        }
+    };
+
     /// a name:mangler map; optimize: use unordered map or some such
-    typedef std::map<std::string, headerMangler> ManglersByName;
+    typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
 
     /// one mangler for each known header
     headerMangler known[HDR_ENUM_END];