]> git.ipfire.org Git - thirdparty/squid.git/blame - src/http/RegisteredHeaders.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / http / RegisteredHeaders.h
CommitLineData
eac61ce1 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
eac61ce1
AJ
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
1139d406
AJ
9#ifndef SQUID_HTTP_REGISTEREDHEADERS_H
10#define SQUID_HTTP_REGISTEREDHEADERS_H
11
d1ea2a11 12#include "base/LookupTable.h"
0a24cff1 13
2c20b348 14#include <iosfwd>
0a24cff1 15#include <vector>
d1ea2a11 16
789217a2
FC
17namespace Http
18{
1139d406 19/// recognized or "known" header fields; and the RFC which defines them (or not)
17437edf 20/// http://www.iana.org/assignments/message-headers/message-headers.xhtml
789217a2 21enum HdrType {
81ab22b6
FC
22 enumBegin_ = 0, // service value for WholeEnum iteration
23 ACCEPT = enumBegin_, /**< RFC 7231 */ /* MUST BE FIRST */
789217a2
FC
24 ACCEPT_CHARSET, /**< RFC 7231 */
25 ACCEPT_ENCODING, /**< RFC 7231 */
26 /*ACCEPT_FEATURES,*/ /* RFC 2295 */
27 ACCEPT_LANGUAGE, /**< RFC 7231 */
28 ACCEPT_RANGES, /**< RFC 7233 */
29 AGE, /**< RFC 7234 */
30 ALLOW, /**< RFC 7231 */
31 ALTERNATE_PROTOCOL, /**< GFE custom header we may have to erase */
32 AUTHENTICATION_INFO, /**< RFC 2617 */
33 AUTHORIZATION, /**< RFC 7235, 4559 */
34 CACHE_CONTROL, /**< RFC 7234 */
35 CONNECTION, /**< RFC 7230 */
36 CONTENT_BASE, /**< obsoleted RFC 2068 */
37 CONTENT_DISPOSITION, /**< RFC 2183, 6266 */
38 CONTENT_ENCODING, /**< RFC 7231 */
39 CONTENT_LANGUAGE, /**< RFC 7231 */
40 CONTENT_LENGTH, /**< RFC 7230 */
41 CONTENT_LOCATION, /**< RFC 7231 */
42 CONTENT_MD5, /**< deprecated, RFC 2616 */
43 CONTENT_RANGE, /**< RFC 7233 */
44 CONTENT_TYPE, /**< RFC 7231 */
45 COOKIE, /**< RFC 6265 header we may need to erase */
46 COOKIE2, /**< obsolete RFC 2965 header we may need to erase */
47 DATE, /**< RFC 7231 */
48 /*DAV,*/ /* RFC 2518 */
49 /*DEPTH,*/ /* RFC 2518 */
50 /*DERIVED_FROM,*/ /* deprecated RFC 2068 */
51 /*DESTINATION,*/ /* RFC 2518 */
52 ETAG, /**< RFC 7232 */
53 EXPECT, /**< RFC 7231 */
54 EXPIRES, /**< RFC 7234 */
55 FORWARDED, /**< RFC 7239 */
56 FROM, /**< RFC 7231 */
57 HOST, /**< RFC 7230 */
58 HTTP2_SETTINGS, /**< RFC 7540 */
59 /*IF,*/ /* RFC 2518 */
60 IF_MATCH, /**< RFC 7232 */
61 IF_MODIFIED_SINCE, /**< RFC 7232 */
62 IF_NONE_MATCH, /**< RFC 7232 */
63 IF_RANGE, /**< RFC 7233 */
64 IF_UNMODIFIED_SINCE, /**< RFC 7232 */
65 KEEP_ALIVE, /**< obsoleted RFC 2068 header we may need to erase */
66 KEY, /**< experimental RFC Draft draft-fielding-http-key-02 */
67 LAST_MODIFIED, /**< RFC 7232 */
68 LINK, /**< RFC 5988 */
69 LOCATION, /**< RFC 7231 */
70 /*LOCK_TOKEN,*/ /* RFC 2518 */
71 MAX_FORWARDS, /**< RFC 7231 */
72 MIME_VERSION, /**< RFC 2045, 7231 */
73 NEGOTIATE, /**< experimental RFC 2295. Why only this one from 2295? */
74 /*OVERWRITE,*/ /* RFC 2518 */
75 ORIGIN, /* CORS Draft specification (see http://www.w3.org/TR/cors/) */
76 PRAGMA, /**< RFC 7234 */
77 PROXY_AUTHENTICATE, /**< RFC 7235 */
78 PROXY_AUTHENTICATION_INFO, /**< RFC 2617 */
79 PROXY_AUTHORIZATION, /**< RFC 7235 */
80 PROXY_CONNECTION, /**< obsolete Netscape header we may need to erase. */
81 PROXY_SUPPORT, /**< RFC 4559 */
82 PUBLIC, /**< RFC 2068 */
83 RANGE, /**< RFC 7233 */
84 REFERER, /**< RFC 7231 */
85 REQUEST_RANGE, /**< some clients use this, sigh */
86 RETRY_AFTER, /**< RFC 7231 */
87 SERVER, /**< RFC 7231 */
88 SET_COOKIE, /**< RFC 6265 header we may need to erase */
89 SET_COOKIE2, /**< obsoleted RFC 2965 header we may need to erase */
90 /*STATUS_URI,*/ /* RFC 2518 */
91 /*TCN,*/ /* experimental RFC 2295 */
92 TE, /**< RFC 7230 */
93 /*TIMEOUT,*/ /* RFC 2518 */
94 TITLE, /* obsolete draft suggested header */
95 TRAILER, /**< RFC 7230 */
96 TRANSFER_ENCODING, /**< RFC 7230 */
97 TRANSLATE, /**< IIS custom header we may need to erase */
98 UNLESS_MODIFIED_SINCE, /**< IIS custom header we may need to erase */
99 UPGRADE, /**< RFC 7230 */
100 USER_AGENT, /**< RFC 7231 */
101 /*VARIANT_VARY,*/ /* experimental RFC 2295 */
102 VARY, /**< RFC 7231 */
103 VIA, /**< RFC 7230 */
104 WARNING, /**< RFC 7234 */
105 WWW_AUTHENTICATE, /**< RFC 7235, 4559 */
106 X_CACHE, /**< Squid custom header */
107 X_CACHE_LOOKUP, /**< Squid custom header. temporary hack that became de-facto. TODO remove */
108 X_FORWARDED_FOR, /**< obsolete Squid custom header, RFC 7239 */
109 X_REQUEST_URI, /**< Squid custom header appended if ADD_X_REQUEST_URI is defined */
110 X_SQUID_ERROR, /**< Squid custom header on generated error responses */
1139d406 111 HDR_X_ACCELERATOR_VARY, /**< obsolete Squid custom header. */
789217a2 112 X_NEXT_SERVICES, /**< Squid custom ICAP header */
789217a2
FC
113 SURROGATE_CAPABILITY, /**< Edge Side Includes (ESI) header */
114 SURROGATE_CONTROL, /**< Edge Side Includes (ESI) header */
115 FRONT_END_HTTPS, /**< MS Exchange custom header we may have to add */
116 FTP_COMMAND, /**< Internal header for FTP command */
117 FTP_ARGUMENTS, /**< Internal header for FTP command arguments */
118 FTP_PRE, /**< Internal header containing leading FTP control response lines */
119 FTP_STATUS, /**< Internal header for FTP reply status */
120 FTP_REASON, /**< Internal header for FTP reply reason */
121 OTHER, /**< internal tag value for "unknown" headers */
81ab22b6
FC
122 BAD_HDR, /**< Invalid header */
123 enumEnd_ // internal tag for end-of-headers
789217a2
FC
124};
125
dc25554a 126/** possible types for http header fields */
a5dd2f99
FC
127enum class HdrFieldType {
128 ftInvalid, /**< to catch nasty errors with hdr_id<->fld_type clashes */
dc25554a
FC
129 ftInt,
130 ftInt64,
131 ftStr,
132 ftDate_1123,
133 ftETag,
134 ftPCc,
135 ftPContRange,
136 ftPRange,
137 ftPSc,
138 ftDate_1123_or_ETag
d9b7869c 139};
dc25554a 140
81ab22b6
FC
141enum HdrKind {
142 None = 0,
143 ListHeader = 1,
144 RequestHeader = 1 << 1,
145 ReplyHeader = 1 << 2,
146 HopByHopHeader = 1 << 3,
147 Denied304Header = 1 << 4, //see comment in HttpReply.cc for meaning
148 GeneralHeader = RequestHeader | ReplyHeader,
149 EntityHeader = RequestHeader | ReplyHeader
150};
151
92991271 152/* POD for HeaderTable */
dc25554a 153class HeaderTableRecord {
81ab22b6
FC
154public:
155 HeaderTableRecord();
156 HeaderTableRecord(const char *n);
157 HeaderTableRecord(const char *, Http::HdrType, Http::HdrFieldType, int /* HdrKind */);
158
dc25554a
FC
159public:
160 const char *name;
789217a2 161 Http::HdrType id;
a5dd2f99 162 Http::HdrFieldType type;
81ab22b6
FC
163 // flags set by constructor from HdrKind parameter
164 bool list; ///<header with field values defined as #(values) in HTTP/1.1
165 bool request; ///<header is a request header
166 bool reply; ///<header is a reply header
167 bool hopbyhop; ///<header is hop by hop
168 bool denied304; ///<header is not to be updated on receiving a 304 in cache revalidation (see HttpReply.cc)
dc25554a
FC
169};
170
81ab22b6 171/** Class for looking up registered header definitions
1da82544 172 *
81ab22b6
FC
173 * Look up HeaderTableRecord's by name or registered header ID.
174 *
175 * Actual records are defined in file RegisteredHeadersHash.gperf, which is
176 * compiled using gperf to RegisteredHeadersHash.cci which is then included
177 * in RegisteredHeaders.cc.
1da82544 178 */
81ab22b6
FC
179class HeaderLookupTable_t {
180public:
181 HeaderLookupTable_t();
182 /// look record type up by name (C-string and length)
183 const HeaderTableRecord& lookup (const char *buf, const std::size_t len) const;
184 /// look record type up by name (std::string)
185 const HeaderTableRecord& lookup (const std::string &key) const {
186 return lookup(key.data(), key.length());
187 }
188 /// look record type up by name (SBuf)
189 const HeaderTableRecord& lookup (const SBuf &key) const {
190 return lookup(key.rawContent(), key.length());
191 }
192 /// look record type up by header ID
193 const HeaderTableRecord& lookup (Http::HdrType id) const {
194 return *(idCache[static_cast<int>(id)]);
195 }
196
197private:
198 void initCache();
199 std::vector<const HeaderTableRecord *> idCache;
200 static const HeaderTableRecord BadHdr; ///<used to signal "not found" from lookups
201};
202extern const HeaderLookupTable_t HeaderLookupTable;
789217a2 203
8cccf1f8 204/// match any known header type, including OTHER and BAD
92991271 205inline bool
1da82544 206any_HdrType_enum_value (const Http::HdrType id)
92991271 207{
81ab22b6 208 return (id >= Http::HdrType::enumBegin_ && id < Http::HdrType::enumEnd_);
92991271
FC
209}
210
8cccf1f8 211/// match any valid header type, including OTHER but not BAD
92991271
FC
212inline bool
213any_valid_header (const Http::HdrType id)
214{
8cccf1f8 215 return (id >= Http::HdrType::ACCEPT && id < Http::HdrType::BAD_HDR);
92991271
FC
216}
217
8cccf1f8
FC
218/// match any registered header type (headers squid knows how to handle),
219/// thus excluding OTHER and BAD
220inline bool
221any_registered_header (const Http::HdrType id)
222{
223 return (id >= Http::HdrType::ACCEPT && id < Http::HdrType::OTHER);
224}
789217a2 225
8cccf1f8 226}; /* namespace Http */
d1ea2a11 227
2c20b348
FC
228/* ostream output for Http::HdrType */
229std::ostream &
230operator<< (std::ostream&, Http::HdrType);
231
1139d406 232#endif /* SQUID_HTTP_REGISTEREDHEADERS_H */
f53969cc 233