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