HeaderMangling.h
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 #ifndef SQUID_SRC_HEADERMANGLING_H
10 #define SQUID_SRC_HEADERMANGLING_H
11 
12 #include "acl/forward.h"
13 #include "format/Format.h"
14 #include "http/RegisteredHeaders.h"
15 
16 #include <functional>
17 #include <list>
18 #include <map>
19 #include <string>
20 #if HAVE_STRINGS_H
21 #include <strings.h>
22 #endif
23 
24 class HeaderWithAcl;
25 class HttpHeader;
26 class HttpHeaderEntry;
27 class StoreEntry;
28 
29 typedef std::list<HeaderWithAcl> HeaderWithAclList;
30 
31 /* Distinguish between Request and Reply (for header mangling) */
32 typedef enum {
35 } req_or_rep_t;
36 
37 // Currently a POD
39 {
40 public:
42  char *replacement;
43 };
44 
47 {
48 public:
51 
53  const headerMangler *find(const HttpHeaderEntry &e) const;
54 
56  headerMangler *track(const char *name);
57 
59  void setReplacement(const char *name, const char *replacementValue);
60 
62  void dumpAccess(StoreEntry *entry, const char *optionName) const;
64  void dumpReplacement(StoreEntry *entry, const char *optionName) const;
65 
66 private:
70  {
71  public:
72  bool operator()(const std::string &lhs, const std::string &rhs) const {
73  return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
74  }
75  };
76 
78  typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
79 
82 
85 
88 
89 private:
90  /* not implemented */
93 };
94 
96 {
97 public:
98  HeaderWithAcl() : aclList(nullptr), valueFormat(nullptr), fieldId(Http::HdrType::BAD_HDR), quoted(false) {}
99 
101  std::string fieldName;
102 
104  std::string fieldValue;
105 
108 
111 
114 
116  bool quoted;
117 };
118 
120 
121 #endif /* SQUID_SRC_HEADERMANGLING_H */
acl_access * access_list
std::list< HeaderWithAcl > HeaderWithAclList
HeaderManglers & operator=(const HeaderManglers &)
void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
ManglersByName custom
one mangler for each custom header
const headerMangler * find(const HttpHeaderEntry &e) const
returns a header mangler for field e or nil if none was specified
headerMangler known[static_cast< int >(Http::HdrType::enumEnd_)]
one mangler for each known header
headerMangler * track(const char *name)
returns a mangler for the named header (known or custom)
Definition: forward.h:17
ACLList * aclList
when the header field should be added (always if nil)
headerMangler all
configured if some mangling ACL applies to all header names
@ ROR_REPLY
A collection of headerMangler objects for a given message kind.
Http::HdrType fieldId
internal ID for "known" headers or HDR_OTHER
std::string fieldName
HTTP header field name.
char * replacement
void dumpReplacement(StoreEntry *entry, const char *optionName) const
report the *_header_replace part of the configuration
@ ROR_REQUEST
void dumpAccess(StoreEntry *entry, const char *optionName) const
report the *_header_access part of the configuration
Format::Format * valueFormat
compiled HTTP header field value (no macros)
std::map< std::string, headerMangler, NoCaseLessThan > ManglersByName
a name:mangler map; optimize: use unordered map or some such
req_or_rep_t
std::string fieldValue
HTTP header field value, possibly with macros.
bool quoted
whether fieldValue may contain macros
bool operator()(const std::string &lhs, const std::string &rhs) const
void setReplacement(const char *name, const char *replacementValue)
updates mangler for the named header with a replacement value

 

Introduction

Documentation

Support

Miscellaneous