2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_HTTP_REGISTEREDHEADERS_H
10 #define SQUID_HTTP_REGISTEREDHEADERS_H
12 #include "base/LookupTable.h"
19 /// recognized or "known" header fields; and the RFC which defines them (or not)
20 /// http://www.iana.org/assignments/message-headers/message-headers.xhtml
22 enumBegin_
= 0, // service value for WholeEnum iteration
23 ACCEPT
= enumBegin_
, /**< RFC 7231 */ /* MUST BE FIRST */
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 */
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 */
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 */
111 HDR_X_ACCELERATOR_VARY
, /**< obsolete Squid custom header. */
112 X_NEXT_SERVICES
, /**< Squid custom ICAP header */
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 */
122 BAD_HDR
, /**< Invalid header */
123 enumEnd_
// internal tag for end-of-headers
126 /** possible types for http header fields */
127 enum class HdrFieldType
{
128 ftInvalid
, /**< to catch nasty errors with hdr_id<->fld_type clashes */
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
152 /* POD for HeaderTable */
153 class HeaderTableRecord
{
156 HeaderTableRecord(const char *n
);
157 HeaderTableRecord(const char *, Http::HdrType
, Http::HdrFieldType
, int /* HdrKind */);
162 Http::HdrFieldType type
;
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)
171 /** Class for looking up registered header definitions
173 * Look up HeaderTableRecord's by name or registered header ID.
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.
179 class HeaderLookupTable_t
{
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());
188 /// look record type up by name (SBuf)
189 const HeaderTableRecord
& lookup (const SBuf
&key
) const {
190 return lookup(key
.rawContent(), key
.length());
192 /// look record type up by header ID
193 const HeaderTableRecord
& lookup (Http::HdrType id
) const {
194 return *(idCache
[static_cast<int>(id
)]);
199 std::vector
<const HeaderTableRecord
*> idCache
;
200 static const HeaderTableRecord BadHdr
; ///<used to signal "not found" from lookups
202 extern const HeaderLookupTable_t HeaderLookupTable
;
204 /// match any known header type, including OTHER and BAD
206 any_HdrType_enum_value (const Http::HdrType id
)
208 return (id
>= Http::HdrType::enumBegin_
&& id
< Http::HdrType::enumEnd_
);
211 /// match any valid header type, including OTHER but not BAD
213 any_valid_header (const Http::HdrType id
)
215 return (id
>= Http::HdrType::ACCEPT
&& id
< Http::HdrType::BAD_HDR
);
218 /// match any registered header type (headers squid knows how to handle),
219 /// thus excluding OTHER and BAD
221 any_registered_header (const Http::HdrType id
)
223 return (id
>= Http::HdrType::ACCEPT
&& id
< Http::HdrType::OTHER
);
226 }; /* namespace Http */
228 /* ostream output for Http::HdrType */
230 operator<< (std::ostream
&, Http::HdrType
);
232 #endif /* SQUID_HTTP_REGISTEREDHEADERS_H */