Squid Web Cache master
Loading...
Searching...
No Matches
HttpHeaderData.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 28 Access Control */
10
11#include "squid.h"
12#include "acl/Acl.h"
13#include "acl/Checklist.h"
14#include "acl/HttpHeaderData.h"
15#include "acl/RegexData.h"
16#include "base/RegexPattern.h"
17#include "cache_cf.h"
18#include "ConfigParser.h"
19#include "debug/Stream.h"
20#include "sbuf/SBuf.h"
21#include "sbuf/StringConvert.h"
22
23/* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
24 * selected header from a given request.
25 *
26 * TODO: This can be generalised by making the type of the regex_rule into a
27 * template parameter - so that we can use different rules types in future.
28 */
29ACLHTTPHeaderData::ACLHTTPHeaderData() : hdrId(Http::HdrType::BAD_HDR), regex_rule(new ACLRegexData)
30{}
31
36
37bool
39{
40 debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
41
42 String value;
44 if (!hdr.has(hdrId))
45 return false;
46 value = hdr.getStrOrList(hdrId);
47 } else {
48 if (!hdr.hasNamed(hdrName, &value))
49 return false;
50 }
51
52 auto cvalue = StringToSBuf(value);
53 return regex_rule->match(cvalue.c_str());
54}
55
58{
59 SBufList sl;
60 sl.push_back(SBuf(hdrName));
61 sl.splice(sl.end(), regex_rule->dump());
62 return sl;
63}
64
65const Acl::Options &
70
71void
78
79bool
84
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
virtual void parse()=0
virtual SBufList dump() const =0
virtual bool match(M)=0
virtual bool empty() const =0
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition Data.h:26
~ACLHTTPHeaderData() override
SBufList dump() const override
ACLData< char const * > * regex_rule
Http::HdrType hdrId
void parse() override
bool empty() const override
const Acl::Options & lineOptions() override
supported ACL "line" options (e.g., "-i")
bool match(const HttpHeader &) override
static char * strtokFile()
String getStrOrList(Http::HdrType id) const
int has(Http::HdrType id) const
bool hasNamed(const SBuf &s, String *value=nullptr) const
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
Definition SBuf.h:94
bool isEmpty() const
Definition SBuf.h:435
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey)
Definition Acl.cc:100
std::vector< const Option * > Options
Definition Options.h:217
Definition forward.h:18
const HeaderLookupTable_t HeaderLookupTable
std::list< SBuf > SBufList
Definition forward.h:23