]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix const-correctness of ACLHTTPHeaderData::match() parameter (#1771)
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 3 Apr 2024 09:25:55 +0000 (09:25 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 4 Apr 2024 15:05:26 +0000 (15:05 +0000)
ACLHTTPHeaderData::match() required a pointer to non-const HttpHeader
but does not (and should not) modify the supplied HttpHeader.

Also removed support for nil HttpHeader in that method. All callers
already require HttpHeader presence. If that changes, it is the _caller_
that should decide what HttpHeader absence means (match, mismatch,
exception/dunno, etc.); ACLHTTPHeaderData does not have enough
information to make the right choice and, hence, should not be asked to
choose.

Also polished related #includes to remove unnecessary ones.

src/acl/HttpHeaderData.cc
src/acl/HttpHeaderData.h
src/acl/HttpRepHeader.cc
src/acl/HttpRepHeader.h
src/acl/HttpReqHeader.cc
src/acl/HttpReqHeader.h
src/http/forward.h

index 2db401e1436bf9844045f285310983c3a3f7d22b..7e1efdab0c43e027b5ea1126e4774c372697fb01 100644 (file)
@@ -36,20 +36,17 @@ ACLHTTPHeaderData::~ACLHTTPHeaderData()
 }
 
 bool
-ACLHTTPHeaderData::match(HttpHeader* hdr)
+ACLHTTPHeaderData::match(const HttpHeader &hdr)
 {
-    if (hdr == nullptr)
-        return false;
-
     debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
 
     String value;
     if (hdrId != Http::HdrType::BAD_HDR) {
-        if (!hdr->has(hdrId))
+        if (!hdr.has(hdrId))
             return false;
-        value = hdr->getStrOrList(hdrId);
+        value = hdr.getStrOrList(hdrId);
     } else {
-        if (!hdr->hasNamed(hdrName, &value))
+        if (!hdr.hasNamed(hdrName, &value))
             return false;
     }
 
index 5036d114dcc9f1d1772acc991e8d033f4d2d3077..fc103ebec1f1c8c5e68be74b33f4f73e769e7c39 100644 (file)
 #include "sbuf/SBuf.h"
 #include "SquidString.h"
 
-class ACLHTTPHeaderData : public ACLData<HttpHeader*>
+class ACLHTTPHeaderData: public ACLData<const HttpHeader &>
 {
     MEMPROXY_CLASS(ACLHTTPHeaderData);
 
 public:
     ACLHTTPHeaderData();
     ~ACLHTTPHeaderData() override;
-    bool match(HttpHeader* hdr) override;
+    bool match(const HttpHeader &) override;
     SBufList dump() const override;
     void parse() override;
     bool empty() const override;
index afa7a52c3f03a044a0b49321d8daade2963a16d1..54c29c7942bc7d7e1d60b3d316b873836fc3c336 100644 (file)
@@ -8,15 +8,12 @@
 
 #include "squid.h"
 #include "acl/FilledChecklist.h"
-#include "acl/HttpHeaderData.h"
 #include "acl/HttpRepHeader.h"
 #include "HttpReply.h"
 
 int
 Acl::HttpRepHeaderCheck::match(ACLChecklist * const ch)
 {
-    const auto checklist = Filled(ch);
-
-    return data->match (&checklist->reply->header);
+    return data->match(Filled(ch)->reply->header);
 }
 
index 845f50b95a2c930ef80194ce1a50a4274156886b..e92ca71da9c83066a72588248624c047e9f9c244 100644 (file)
 
 #include "acl/Data.h"
 #include "acl/ParameterizedNode.h"
-#include "HttpHeader.h"
+#include "http/forward.h"
 
 namespace Acl
 {
 
 /// a "rep_header" ACL
-class HttpRepHeaderCheck: public ParameterizedNode< ACLData<HttpHeader*> >
+class HttpRepHeaderCheck: public ParameterizedNode< ACLData<const HttpHeader &> >
 {
 public:
     /* Acl::Node API */
index 1d8bf42a7f27a5c7f48866b1dc05a843dca1eab2..b6d3a7da8c62377fb500249449e3ef8eaaf4ef84 100644 (file)
@@ -8,15 +8,12 @@
 
 #include "squid.h"
 #include "acl/FilledChecklist.h"
-#include "acl/HttpHeaderData.h"
 #include "acl/HttpReqHeader.h"
 #include "HttpRequest.h"
 
 int
 Acl::HttpReqHeaderCheck::match(ACLChecklist * const ch)
 {
-    const auto checklist = Filled(ch);
-
-    return data->match (&checklist->request->header);
+    return data->match(Filled(ch)->request->header);
 }
 
index e313a06de62581d02d3de016ed3b33c200b4a496..1e3f0d394ba07f7de59e64b8389d34d2edb380bd 100644 (file)
 
 #include "acl/Data.h"
 #include "acl/ParameterizedNode.h"
-#include "HttpHeader.h"
+#include "http/forward.h"
 
 namespace Acl
 {
 
 /// a "req_header" ACL
-class HttpReqHeaderCheck: public ParameterizedNode< ACLData<HttpHeader*> >
+class HttpReqHeaderCheck: public ParameterizedNode< ACLData<const HttpHeader &> >
 {
 public:
     /* Acl::Node API */
index ad9cd5474203e5275d3110f560ea148ae4bda423..e5bf185588d98076bd60ba0958787d725e1e0781 100644 (file)
@@ -39,6 +39,8 @@ typedef enum {
 
 class HttpHdrSc;
 
+class HttpHeader;
+
 class HttpRequestMethod;
 
 class HttpRequest;