HttpHeaderTools.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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_HTTPHEADERTOOLS_H
10 #define SQUID_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:
51  ~HeaderManglers();
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:
70  class NoCaseLessThan: public std::binary_function<std::string, std::string, bool>
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 
82  headerMangler known[static_cast<int>(Http::HdrType::enumEnd_)];
83 
85  ManglersByName custom;
86 
89 
90 private:
91  /* not implemented */
93  HeaderManglers &operator =(const HeaderManglers &);
94 };
95 
97 {
98 public:
99  HeaderWithAcl() : aclList(NULL), valueFormat(NULL), 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 
134 void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep);
135 
136 #endif
137 
req_or_rep_t
std::string fieldValue
HTTP header field value, possibly with macros.
Definition: SBuf.h:86
A collection of headerMangler objects for a given message kind.
#define ACLList
Definition: forward.h:45
bool httpHeaderParseOffset(const char *start, int64_t *offPtr, char **endPtr=nullptr)
bool httpHeaderHasConnDir(const HttpHeader *hdr, const SBuf &directive)
void httpHdrMangleList(HttpHeader *, HttpRequest *, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
headerMangler all
configured if some mangling ACL applies to all header names
Format::Format * valueFormat
compiled HTTP header field value (no macros)
ManglersByName custom
one mangler for each custom header
std::list< HeaderWithAcl > HeaderWithAclList
Http::HdrType fieldId
internal ID for "known" headers or HDR_OTHER
#define PRINTF_FORMAT_ARG3
bool operator()(const std::string &lhs, const std::string &rhs) const
bool quoted
whether fieldValue may contain macros
std::string fieldName
HTTP header field name.
std::map< std::string, headerMangler, NoCaseLessThan > ManglersByName
a name:mangler map; optimize: use unordered map or some such
acl_access * access_list
ACLList * aclList
when the header field should be added (always if nil)
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...) PRINTF_FORMAT_ARG3
const char * getStringPrefix(const char *str, size_t len)
int httpHeaderParseInt(const char *start, int *val)
#define acl_access
Definition: forward.h:44
Definition: forward.h:21
#define NULL
Definition: types.h:166
#define false
Definition: GnuRegex.c:233

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors