HttpHeaderTools.h
Go to the documentation of this file.
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_HTTPHEADERTOOLS_H
10 #define SQUID_SRC_HTTPHEADERTOOLS_H
11 
12 #include "acl/forward.h"
13 #include "format/Format.h"
14 #include "HttpHeader.h"
15 #include "sbuf/forward.h"
16 
17 #include <functional>
18 #include <list>
19 #include <map>
20 #include <string>
21 #if HAVE_STRINGS_H
22 #include <strings.h>
23 #endif
24 
25 class HeaderWithAcl;
26 class HttpHeader;
27 class HttpRequest;
28 class StoreEntry;
29 
30 typedef std::list<HeaderWithAcl> HeaderWithAclList;
31 
32 /* Distinguish between Request and Reply (for header mangling) */
33 typedef enum {
36 } req_or_rep_t;
37 
38 // Currently a POD
40 {
41 public:
43  char *replacement;
44 };
45 
48 {
49 public:
52 
54  const headerMangler *find(const HttpHeaderEntry &e) const;
55 
57  headerMangler *track(const char *name);
58 
60  void setReplacement(const char *name, const char *replacementValue);
61 
63  void dumpAccess(StoreEntry *entry, const char *optionName) const;
65  void dumpReplacement(StoreEntry *entry, const char *optionName) const;
66 
67 private:
71  {
72  public:
73  bool operator()(const std::string &lhs, const std::string &rhs) const {
74  return strcasecmp(lhs.c_str(), rhs.c_str()) < 0;
75  }
76  };
77 
79  typedef std::map<std::string, headerMangler, NoCaseLessThan> ManglersByName;
80 
83 
86 
89 
90 private:
91  /* not implemented */
94 };
95 
97 {
98 public:
99  HeaderWithAcl() : aclList(nullptr), valueFormat(nullptr), fieldId(Http::HdrType::BAD_HDR), quoted(false) {}
100 
102  std::string fieldName;
103 
105  std::string fieldValue;
106 
109 
112 
115 
117  bool quoted;
118 };
119 
126 bool httpHeaderParseOffset(const char *start, int64_t *offPtr, char **endPtr = nullptr);
127 
128 bool httpHeaderHasConnDir(const HttpHeader * hdr, const SBuf &directive);
129 int httpHeaderParseInt(const char *start, int *val);
130 void httpHeaderPutStrf(HttpHeader * hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3;
131 
132 const char *getStringPrefix(const char *str, size_t len);
133 
135 
136 #endif /* SQUID_SRC_HTTPHEADERTOOLS_H */
137 
acl_access * access_list
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3
const char * getStringPrefix(const char *str, size_t len)
HeaderManglers & operator=(const HeaderManglers &)
bool httpHeaderParseOffset(const char *start, int64_t *offPtr, char **endPtr=nullptr)
std::list< HeaderWithAcl > HeaderWithAclList
void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
ManglersByName custom
one mangler for each custom header
Definition: SBuf.h:93
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
int httpHeaderParseInt(const char *start, int *val)
@ ROR_REQUEST
A collection of headerMangler objects for a given message kind.
req_or_rep_t
#define PRINTF_FORMAT_ARG3
Http::HdrType fieldId
internal ID for "known" headers or HDR_OTHER
std::string fieldName
HTTP header field name.
void dumpReplacement(StoreEntry *entry, const char *optionName) const
report the *_header_replace part of the configuration
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
std::string fieldValue
HTTP header field value, possibly with macros.
bool quoted
whether fieldValue may contain macros
bool httpHeaderHasConnDir(const HttpHeader *hdr, const SBuf &directive)
bool operator()(const std::string &lhs, const std::string &rhs) const
@ ROR_REPLY
void setReplacement(const char *name, const char *replacementValue)
updates mangler for the named header with a replacement value

 

Introduction

Documentation

Support

Miscellaneous