HttpHeaderTools.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 {
35  ROR_REPLY
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:
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 
83 
86 
89 
90 private:
91  /* not implemented */
94 };
95 
97 {
98 public:
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
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:87
const headerMangler * find(const HttpHeaderEntry &e) const
returns a header mangler for field e or nil if none was specified
#define ACLList
Definition: forward.h:46
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:22
ACLList * aclList
when the header field should be added (always if nil)
headerMangler all
configured if some mangling ACL applies to all header names
#define NULL
Definition: types.h:166
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
HeaderManglers(const HeaderManglers &)
#define acl_access
Definition: forward.h:45
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)
#define false
Definition: GnuRegex.c:233
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

Web Site Translations

Mirrors