Search squid archive

Re: squid 3.2.7 + icap + request_header_access - not working as expected under some circumstances (bug?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 05/15/2013 07:41 AM, Amos Jeffries wrote:
> On 16/05/2013 1:06 a.m., Martin Sperl wrote:
>> Hi!
>>
>> We came across a strange "bug" in squid in regards to icap and
>> request_header access.
> 
> It is a bug alright. Header names are supposed to be case-insensitive.

The attached patches fix this bug in Squid v3.2 and trunk.

Disclaimers: I only tested the trunk patch. I do not think this is
related to ICAP (the bug affects all Squid configurations that use
header_access directives).


HTH,

Alex.

Use case-insensitive comparison for header names in *_header_access
and *_header_replace directives.

=== modified file 'src/HttpHeaderTools.h'
--- src/HttpHeaderTools.h	2012-07-13 11:53:18 +0000
+++ src/HttpHeaderTools.h	2013-05-15 17:01:55 +0000
@@ -1,12 +1,18 @@
 #ifndef SQUID_HTTPHEADERTOOLS_H
 #define SQUID_HTTPHEADERTOOLS_H
 
+#if HAVE_FUNCTIONAL
+#include <functional>
+#endif
 #if HAVE_MAP
 #include <map>
 #endif
 #if HAVE_STRING
 #include <string>
 #endif
+#if HAVE_STRINGS_H
+#include <strings.h>
+#endif
 
 class acl_access;
 struct _header_mangler {
@@ -39,8 +45,17 @@
     void dumpReplacement(StoreEntry *entry, const char *optionName) const;
 
 private:
+    /// Case-insensitive std::string comparison functor.
+    /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
+    class NoCaseLess: 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, header_mangler> ManglersByName;
+    typedef std::map<std::string, header_mangler, NoCaseLess> ManglersByName;
 
     /// one mangler for each known header
     header_mangler known[HDR_ENUM_END];

Use case-insensitive comparison for header names in *_header_access
and *_header_replace directives.

=== modified file 'src/HttpHeaderTools.h'
--- src/HttpHeaderTools.h	2013-02-17 09:31:18 +0000
+++ src/HttpHeaderTools.h	2013-05-15 16:31:39 +0000
@@ -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 @@
     void dumpReplacement(StoreEntry *entry, const char *optionName) const;
 
 private:
+    /// Case-insensitive std::string comparison functor.
+    /// Fast version recommended by Meyers' "Effective STL" for ASCII c-strings.
+    class NoCaseLess: 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, NoCaseLess> ManglersByName;
 
     /// one mangler for each known header
     headerMangler known[HDR_ENUM_END];


[Index of Archives]     [Linux Audio Users]     [Samba]     [Big List of Linux Books]     [Linux USB]     [Yosemite News]

  Powered by Linux