From 47c9c9376d11a828a675e96ad6fa96c9fbcbceb0 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Wed, 3 Apr 2024 09:25:55 +0000 Subject: [PATCH] Fix const-correctness of ACLHTTPHeaderData::match() parameter (#1771) 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 | 11 ++++------- src/acl/HttpHeaderData.h | 4 ++-- src/acl/HttpRepHeader.cc | 5 +---- src/acl/HttpRepHeader.h | 4 ++-- src/acl/HttpReqHeader.cc | 5 +---- src/acl/HttpReqHeader.h | 4 ++-- src/http/forward.h | 2 ++ 7 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/acl/HttpHeaderData.cc b/src/acl/HttpHeaderData.cc index 2db401e143..7e1efdab0c 100644 --- a/src/acl/HttpHeaderData.cc +++ b/src/acl/HttpHeaderData.cc @@ -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; } diff --git a/src/acl/HttpHeaderData.h b/src/acl/HttpHeaderData.h index 5036d114dc..fc103ebec1 100644 --- a/src/acl/HttpHeaderData.h +++ b/src/acl/HttpHeaderData.h @@ -14,14 +14,14 @@ #include "sbuf/SBuf.h" #include "SquidString.h" -class ACLHTTPHeaderData : public ACLData +class ACLHTTPHeaderData: public ACLData { 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; diff --git a/src/acl/HttpRepHeader.cc b/src/acl/HttpRepHeader.cc index afa7a52c3f..54c29c7942 100644 --- a/src/acl/HttpRepHeader.cc +++ b/src/acl/HttpRepHeader.cc @@ -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); } diff --git a/src/acl/HttpRepHeader.h b/src/acl/HttpRepHeader.h index 845f50b95a..e92ca71da9 100644 --- a/src/acl/HttpRepHeader.h +++ b/src/acl/HttpRepHeader.h @@ -11,13 +11,13 @@ #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 > +class HttpRepHeaderCheck: public ParameterizedNode< ACLData > { public: /* Acl::Node API */ diff --git a/src/acl/HttpReqHeader.cc b/src/acl/HttpReqHeader.cc index 1d8bf42a7f..b6d3a7da8c 100644 --- a/src/acl/HttpReqHeader.cc +++ b/src/acl/HttpReqHeader.cc @@ -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); } diff --git a/src/acl/HttpReqHeader.h b/src/acl/HttpReqHeader.h index e313a06de6..1e3f0d394b 100644 --- a/src/acl/HttpReqHeader.h +++ b/src/acl/HttpReqHeader.h @@ -11,13 +11,13 @@ #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 > +class HttpReqHeaderCheck: public ParameterizedNode< ACLData > { public: /* Acl::Node API */ diff --git a/src/http/forward.h b/src/http/forward.h index ad9cd54742..e5bf185588 100644 --- a/src/http/forward.h +++ b/src/http/forward.h @@ -39,6 +39,8 @@ typedef enum { class HttpHdrSc; +class HttpHeader; + class HttpRequestMethod; class HttpRequest; -- 2.47.2