RegisteredHeaders.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_HTTP_REGISTEREDHEADERS_H
10 #define SQUID_SRC_HTTP_REGISTEREDHEADERS_H
11 
12 #include "base/LookupTable.h"
13 
14 #include <iosfwd>
15 #include <vector>
16 
17 namespace Http
18 {
21 enum HdrType {
22  enumBegin_ = 0, // service value for WholeEnum iteration
23  ACCEPT = enumBegin_, /* MUST BE FIRST */
26  /*ACCEPT_FEATURES,*/ /* RFC 2295 */
29  AGE,
49  DATE,
50  /*DAV,*/ /* RFC 2518 */
51  /*DEPTH,*/ /* RFC 2518 */
52  /*DERIVED_FROM,*/ /* deprecated RFC 2068 */
53  /*DESTINATION,*/ /* RFC 2518 */
54  ETAG,
58  FROM,
59  HOST,
60  /*HTTP2_SETTINGS,*/ /* obsolete RFC 7540 */
61  /*IF,*/ /* RFC 2518 */
68  KEY,
70  LINK,
72  /*LOCK_TOKEN,*/ /* RFC 2518 */
76  /*OVERWRITE,*/ /* RFC 2518 */
77  ORIGIN, /* CORS Draft specification (see http://www.w3.org/TR/cors/) */
93  /*STATUS_URI,*/ /* RFC 2518 */
94  /*TCN,*/ /* experimental RFC 2295 */
95  TE,
96  /*TIMEOUT,*/ /* RFC 2518 */
97  TITLE, /* obsolete draft suggested header */
104  /*VARIANT_VARY,*/ /* experimental RFC 2295 */
106  VIA,
122  enumEnd_ // internal tag for end-of-headers
123 };
124 
126 enum class HdrFieldType {
127  ftInvalid,
128  ftInt,
129  ftInt64,
130  ftStr,
131  ftDate_1123,
132  ftETag,
133  ftPCc,
134  ftPContRange,
135  ftPRange,
136  ftPSc,
138 };
139 
140 enum HdrKind {
141  None = 0,
143  RequestHeader = 1 << 1,
144  ReplyHeader = 1 << 2,
145  HopByHopHeader = 1 << 3,
146  Denied304Header = 1 << 4, //see comment in HttpReply.cc for meaning
149 };
150 
151 /* POD for HeaderTable */
153 public:
154  HeaderTableRecord() = default;
155  HeaderTableRecord(const char *n);
156  HeaderTableRecord(const char *, Http::HdrType, Http::HdrFieldType, int /* HdrKind */);
157 
158  const char *name = "";
161  // flags set by constructor from HdrKind parameter
162  bool list = false;;
163  bool request = false;
164  bool reply = false;
165  bool hopbyhop = false;
166  bool denied304 = false;
167 };
168 
178 public:
181  const HeaderTableRecord& lookup (const char *buf, const std::size_t len) const;
183  const HeaderTableRecord& lookup (const std::string &key) const {
184  return lookup(key.data(), key.length());
185  }
187  const HeaderTableRecord& lookup (const SBuf &key) const {
188  return lookup(key.rawContent(), key.length());
189  }
192  return *(idCache[static_cast<int>(id)]);
193  }
194 
195 private:
196  void initCache();
197  std::vector<const HeaderTableRecord *> idCache;
198  static const HeaderTableRecord BadHdr;
199 };
201 
203 inline bool
205 {
206  return (id >= Http::HdrType::enumBegin_ && id < Http::HdrType::enumEnd_);
207 }
208 
210 inline bool
212 {
213  return (id >= Http::HdrType::ACCEPT && id < Http::HdrType::BAD_HDR);
214 }
215 
218 inline bool
220 {
221  return (id >= Http::HdrType::ACCEPT && id < Http::HdrType::OTHER);
222 }
223 
224 std::ostream &operator <<(std::ostream &, HdrType);
225 
226 }; /* namespace Http */
227 
228 #endif /* SQUID_SRC_HTTP_REGISTEREDHEADERS_H */
229 
bool request
header with field values defined as #(values) in HTTP/1.1
bool any_registered_header(const Http::HdrType id)
@ SURROGATE_CONTROL
@ HDR_X_ACCELERATOR_VARY
bool hopbyhop
header is hop by hop
@ PROXY_CONNECTION
Definition: SBuf.h:93
@ CONTENT_ENCODING
@ CONTENT_LANGUAGE
std::vector< const HeaderTableRecord * > idCache
Definition: forward.h:17
@ AUTHENTICATION_INFO
@ IF_MODIFIED_SINCE
int const char size_t
Definition: stub_liblog.cc:83
bool denied304
header is not to be updated on receiving a 304 in cache revalidation (see HttpReply....
@ CONTENT_LENGTH
bool any_HdrType_enum_value(const Http::HdrType id)
match any known header type, including OTHER and BAD
@ WWW_AUTHENTICATE
const char * rawContent() const
Definition: SBuf.cc:509
@ ACCEPT_LANGUAGE
@ CONTENT_LOCATION
static const HeaderTableRecord BadHdr
used to signal "not found" from lookups
bool any_valid_header(const Http::HdrType id)
match any valid header type, including OTHER but not BAD
@ IF_UNMODIFIED_SINCE
@ TRANSFER_ENCODING
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:419
@ ACCEPT_ENCODING
const HeaderLookupTable_t HeaderLookupTable
bool reply
header is a reply header
std::ostream & operator<<(std::ostream &, const TunnelerAnswer &)
@ PROXY_AUTHENTICATE
@ CONTENT_DISPOSITION
@ PROXY_AUTHENTICATION_INFO
@ SURROGATE_CAPABILITY
const HeaderTableRecord & lookup(const SBuf &key) const
look record type up by name (SBuf)
@ ALTERNATE_PROTOCOL
const HeaderTableRecord & lookup(Http::HdrType id) const
look record type up by header ID
@ UNLESS_MODIFIED_SINCE
@ ACCEPT_CHARSET
const HeaderTableRecord & lookup(const std::string &key) const
look record type up by name (std::string)
@ PROXY_AUTHORIZATION
Http::HdrFieldType type

 

Introduction

Documentation

Support

Miscellaneous