]> 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>
Sun, 19 May 2013 03:19:50 +0000 (21:19 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 19 May 2013 03:19:50 +0000 (21:19 -0600)
src/HttpHeaderTools.h

index bdaf6f7da6741a4c3a6d0d8c0d816815d397305c..01b1b710d0da2119f67a2aac2e0de1a0074a43c4 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,18 @@ 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];