RegisteredHeaders.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_HTTP_REGISTEREDHEADERS_H
10 #define SQUID_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,
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/) */
92  /*STATUS_URI,*/ /* RFC 2518 */
93  /*TCN,*/ /* experimental RFC 2295 */
94  TE,
95  /*TIMEOUT,*/ /* RFC 2518 */
96  TITLE, /* obsolete draft suggested header */
103  /*VARIANT_VARY,*/ /* experimental RFC 2295 */
105  VIA,
123  enumEnd_ // internal tag for end-of-headers
124 };
125 
127 enum class HdrFieldType {
128  ftInvalid,
129  ftInt,
130  ftInt64,
131  ftStr,
132  ftDate_1123,
133  ftETag,
134  ftPCc,
135  ftPContRange,
136  ftPRange,
137  ftPSc,
139 };
140 
141 enum HdrKind {
142  None = 0,
144  RequestHeader = 1 << 1,
145  ReplyHeader = 1 << 2,
146  HopByHopHeader = 1 << 3,
147  Denied304Header = 1 << 4, //see comment in HttpReply.cc for meaning
150 };
151 
152 /* POD for HeaderTable */
154  HeaderTableRecord() = default;
155  HeaderTableRecord(const char *n);
156  HeaderTableRecord(const char *, Http::HdrType, Http::HdrFieldType, int /* HdrKind */);
157 
158  const char *name = "";
160  Http::HdrFieldType type = HdrFieldType::ftInvalid;
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 }; /* namespace Http */
225 
226 /* ostream output for Http::HdrType */
227 std::ostream &
228 operator<< (std::ostream&, Http::HdrType);
229 
230 #endif /* SQUID_HTTP_REGISTEREDHEADERS_H */
231 
bool any_registered_header(const Http::HdrType id)
@ SURROGATE_CONTROL
@ HDR_X_ACCELERATOR_VARY
@ PROXY_CONNECTION
Definition: SBuf.h:87
@ HTTP2_SETTINGS
@ CONTENT_ENCODING
@ CONTENT_LANGUAGE
std::vector< const HeaderTableRecord * > idCache
Definition: forward.h:22
@ AUTHENTICATION_INFO
@ IF_MODIFIED_SINCE
int const char size_t
Definition: stub_liblog.cc:86
@ CONTENT_LENGTH
bool any_HdrType_enum_value(const Http::HdrType id)
match any known header type, including OTHER and BAD
@ WWW_AUTHENTICATE
bool hopbyhop
header is hop by hop
const char * rawContent() const
Definition: SBuf.cc:509
@ ACCEPT_LANGUAGE
Http::HdrFieldType type
@ 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
std::ostream & operator<<(std::ostream &, Http::HdrType)
@ 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)
bool reply
header is a reply header
size_type length() const
Returns the number of bytes stored in SBuf.
Definition: SBuf.h:408
@ ACCEPT_ENCODING
const HeaderLookupTable_t HeaderLookupTable
bool request
header with field values defined as #(values) in HTTP/1.1
@ PROXY_AUTHENTICATE
@ CONTENT_DISPOSITION
@ PROXY_AUTHENTICATION_INFO
@ SURROGATE_CAPABILITY
@ enumBegin_
Definition: icp_opcode.h:14
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
bool denied304
header is not to be updated on receiving a 304 in cache revalidation (see HttpReply....
@ ACCEPT_CHARSET
const HeaderTableRecord & lookup(const std::string &key) const
look record type up by name (std::string)
@ PROXY_AUTHORIZATION

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors