]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/RequestHeaderStrategy.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / acl / RequestHeaderStrategy.h
1 /*
2 * Copyright (C) 1996-2023 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 #ifndef SQUID_SRC_ACL_REQUESTHEADERSTRATEGY_H
10 #define SQUID_SRC_ACL_REQUESTHEADERSTRATEGY_H
11
12 #include "acl/Data.h"
13 #include "acl/FilledChecklist.h"
14 #include "acl/ParameterizedNode.h"
15 #include "HttpRequest.h"
16
17 namespace Acl
18 {
19
20 /// matches the value of a given request header (e.g., "browser" or "referer_regex")
21 template <Http::HdrType header>
22 class RequestHeaderCheck: public ParameterizedNode< ACLData<const char *> >
23 {
24 public:
25 /* Acl::Node API */
26 int match(ACLChecklist *) override;
27 bool requiresRequest() const override {return true;}
28 };
29
30 } // namespace Acl
31
32 template <Http::HdrType header>
33 int
34 Acl::RequestHeaderCheck<header>::match(ACLChecklist * const ch)
35 {
36 const auto checklist = Filled(ch);
37
38 char const *theHeader = checklist->request->header.getStr(header);
39
40 if (nullptr == theHeader)
41 return 0;
42
43 return data->match(theHeader);
44 }
45
46 #endif /* SQUID_SRC_ACL_REQUESTHEADERSTRATEGY_H */
47