]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeader.h
Bug 3685: Squid hangs in ClassCBucket::update
[thirdparty/squid.git] / src / HttpHeader.h
CommitLineData
e6ccf245 1/*
e6ccf245 2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
26ac0430 19 *
e6ccf245 20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
26ac0430 24 *
e6ccf245 25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30
31#ifndef SQUID_HTTPHEADER_H
32#define SQUID_HTTPHEADER_H
33
528b2c61 34/* because we pass a spec by value */
25b6a907 35#include "HttpHeaderMask.h"
43ca19e0 36#include "MemPool.h"
71b673d4 37#include "SquidString.h"
43ca19e0 38
696a257c 39/* class forward declarations */
696a257c 40class HttpHdrCc;
71b673d4 41class HttpHdrContRange;
696a257c 42class HttpHdrRange;
71b673d4 43class HttpHdrSc;
43ca19e0 44class Packer;
f734cda2 45class StoreEntry;
696a257c 46
e6ccf245 47/* constant attributes of http header fields */
62e76326 48
759fac4b 49/// recognized or "known" header fields; and the RFC which defines them (or not)
25b6a907 50typedef enum {
51 HDR_BAD_HDR = -1,
759fac4b
AJ
52 HDR_ACCEPT = 0, /**< RFC 2608, 2616 */
53 HDR_ACCEPT_CHARSET, /**< RFC 2608, 2616 */
54 HDR_ACCEPT_ENCODING, /**< RFC 2608, 2616 */
55 /*HDR_ACCEPT_FEATURES,*/ /* experimental RFC 2295 */
56 HDR_ACCEPT_LANGUAGE, /**< RFC 2608, 2616 */
57 HDR_ACCEPT_RANGES, /**< RFC 2608, 2616 */
58 HDR_AGE, /**< RFC 2608, 2616 */
59 HDR_ALLOW, /**< RFC 2608, 2616 */
60 /*HDR_ALTERNATES,*/ /* deprecated RFC 2068, 2295 */
61 HDR_AUTHORIZATION, /**< RFC 2608, 2616, 4559 */
62 HDR_CACHE_CONTROL, /**< RFC 2608, 2616 */
63 HDR_CONNECTION, /**< RFC 2608, 2616 */
64 HDR_CONTENT_BASE, /**< RFC 2608 */
65 HDR_CONTENT_DISPOSITION, /**< RFC 2183, 2616 */
66 HDR_CONTENT_ENCODING, /**< RFC 2608, 2616 */
67 HDR_CONTENT_LANGUAGE, /**< RFC 2608, 2616 */
68 HDR_CONTENT_LENGTH, /**< RFC 2608, 2616 */
69 HDR_CONTENT_LOCATION, /**< RFC 2608, 2616 */
70 HDR_CONTENT_MD5, /**< RFC 2608, 2616 */
71 HDR_CONTENT_RANGE, /**< RFC 2608, 2616 */
72 HDR_CONTENT_TYPE, /**< RFC 2608, 2616 */
73 /*HDR_CONTENT_VERSION,*/ /* deprecated RFC 2608 header. */
74 HDR_COOKIE, /**< de-facto and RFC 2965 header we may need to erase */
75 HDR_COOKIE2, /**< obsolete RFC 2965 header we may need to erase */
76 HDR_DATE, /**< RFC 2608, 2616 */
77 /*HDR_DAV,*/ /* RFC 2518 */
78 /*HDR_DEPTH,*/ /* RFC 2518 */
79 /*HDR_DERIVED_FROM,*/ /* deprecated RFC 2608 */
80 /*HDR_DESTINATION,*/ /* RFC 2518 */
81 HDR_ETAG, /**< RFC 2608, 2616 */
82 HDR_EXPECT, /**< RFC 2616, 2616 */
83 HDR_EXPIRES, /**< RFC 2608, 2616 */
84 HDR_FROM, /**< RFC 2608, 2616 */
85 HDR_HOST, /**< RFC 2608, 2616 */
86 /*HDR_IF,*/ /* RFC 2518 */
87 HDR_IF_MATCH, /**< RFC 2608, 2616 */
88 HDR_IF_MODIFIED_SINCE, /**< RFC 2608, 2616 */
89 HDR_IF_NONE_MATCH, /**< RFC 2608, 2616 */
90 HDR_IF_RANGE, /**< RFC 2608, 2616 */
debd58cb 91 /*HDR_IF_UNMODIFIED_SINCE,*/ /**< RFC 2608, 2616 */
759fac4b
AJ
92 HDR_KEEP_ALIVE, /**< obsolete HTTP/1.0 header we may need to erase */
93 HDR_LAST_MODIFIED, /**< RFC 2608, 2616 */
94 HDR_LINK, /**< RFC 2068 */
95 HDR_LOCATION, /**< RFC 2608, 2616 */
96 /*HDR_LOCK_TOKEN,*/ /* RFC 2518 */
97 HDR_MAX_FORWARDS, /**< RFC 2608, 2616 */
98 HDR_MIME_VERSION, /**< RFC 2626 */
99 HDR_NEGOTIATE, /**< experimental RFC 2295. Why only this one from 2295? */
100 /*HDR_OVERWRITE,*/ /* RFC 2518 */
3865965d 101 HDR_ORIGIN, /* CORS Draft specification (see http://www.w3.org/TR/cors/) */
759fac4b
AJ
102 HDR_PRAGMA, /**< deprecated RFC 2068,2616 header we may need to erase */
103 HDR_PROXY_AUTHENTICATE, /**< RFC 2608, 2616, 2617 */
104 HDR_PROXY_AUTHENTICATION_INFO, /**< RFC 2617 */
105 HDR_PROXY_AUTHORIZATION, /**< RFC 2608, 2616, 2617 */
106 HDR_PROXY_CONNECTION, /**< obsolete Netscape header we may need to erase. */
107 HDR_PROXY_SUPPORT, /**< RFC 4559 */
108 HDR_PUBLIC, /**< RFC 2608 */
109 HDR_RANGE, /**< RFC 2608, 2616 */
759fac4b 110 HDR_REFERER, /**< RFC 2608, 2616 */
debd58cb 111 HDR_REQUEST_RANGE, /**< some clients use this, sigh */
759fac4b
AJ
112 HDR_RETRY_AFTER, /**< RFC 2608, 2616 */
113 HDR_SERVER, /**< RFC 2608, 2616 */
114 HDR_SET_COOKIE, /**< de-facto standard header we may need to erase */
115 HDR_SET_COOKIE2, /**< obsolete RFC 2965 header we may need to erase */
116 /*HDR_STATUS_URI,*/ /* RFC 2518 */
117 /*HDR_TCN,*/ /* experimental RFC 2295 */
118 HDR_TE, /**< RFC 2616 */
119 /*HDR_TIMEOUT,*/ /* RFC 2518 */
120 HDR_TITLE, /* obsolete draft suggested header */
121 HDR_TRAILER, /**< RFC 2616 */
122 HDR_TRANSFER_ENCODING, /**< RFC 2608, 2616 */
123 HDR_TRANSLATE, /**< IIS custom header we may need to erase */
124 HDR_UNLESS_MODIFIED_SINCE, /**< IIS custom header we may need to erase */
125 HDR_UPGRADE, /**< RFC 2608, 2616 */
126 /*HDR_URI,*/ /* obsolete RFC 2068 header */
127 HDR_USER_AGENT, /**< RFC 2608, 2616 */
128 /*HDR_VARIANT_VARY,*/ /* experimental RFC 2295 */
129 HDR_VARY, /**< RFC 2608, 2616 */
130 HDR_VIA, /**< RFC 2608, 2616 */
131 HDR_WARNING, /**< RFC 2608, 2616 */
132 HDR_WWW_AUTHENTICATE, /**< RFC 2608, 2616, 2617, 4559 */
133 HDR_AUTHENTICATION_INFO, /**< RFC 2617 */
134 HDR_X_CACHE, /**< Squid custom header */
135 HDR_X_CACHE_LOOKUP, /**< Squid custom header. temporary hack that became de-facto. TODO remove */
136 HDR_X_FORWARDED_FOR, /**< Squid custom header */
137 HDR_X_REQUEST_URI, /**< Squid custom header appended if ADD_X_REQUEST_URI is defined */
138 HDR_X_SQUID_ERROR, /**< Squid custom header on generated error responses */
25b6a907 139#if X_ACCELERATOR_VARY
759fac4b 140 HDR_X_ACCELERATOR_VARY, /**< obsolete Squid custom header. */
a22e6cd3
AR
141#endif
142#if USE_ADAPTATION
759fac4b 143 HDR_X_NEXT_SERVICES, /**< Squid custom ICAP header */
25b6a907 144#endif
759fac4b
AJ
145 HDR_SURROGATE_CAPABILITY, /**< Edge Side Includes (ESI) header */
146 HDR_SURROGATE_CONTROL, /**< Edge Side Includes (ESI) header */
147 HDR_FRONT_END_HTTPS, /**< MS Exchange custom header we may have to add */
148 HDR_OTHER, /**< internal tag value for "unknown" headers */
25b6a907 149 HDR_ENUM_END
150} http_hdr_type;
151
63be0a78 152/** possible types for http header fields */
25b6a907 153typedef enum {
63be0a78 154 ftInvalid = HDR_ENUM_END, /**< to catch nasty errors with hdr_id<->fld_type clashes */
25b6a907 155 ftInt,
47f6e231 156 ftInt64,
25b6a907 157 ftStr,
158 ftDate_1123,
159 ftETag,
160 ftPCc,
161 ftPContRange,
162 ftPRange,
163 ftPSc,
164 ftDate_1123_or_ETag
165} field_type;
166
63be0a78 167/** Possible owners of http header */
25b6a907 168typedef enum {
0b57cb3d 169 hoNone =0,
25b6a907 170#if USE_HTCP
171 hoHtcpReply,
172#endif
173 hoRequest,
02259ff8
CT
174 hoReply,
175#if USE_SSL
176 hoErrorDetail,
177#endif
d7f4a0b7 178 hoNote,
02259ff8 179 hoEnd
25b6a907 180} http_hdr_owner_type;
181
001d55dc 182// currently a POD
1b2f0924
FC
183class HttpHeaderFieldAttrs
184{
09bbee4c 185public:
e6ccf245 186 const char *name;
187 http_hdr_type id;
188 field_type type;
189};
190
63be0a78 191/** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
985c86bc 192typedef ssize_t HttpHeaderPos;
193
194/* use this and only this to initialize HttpHeaderPos */
195#define HttpHeaderInitPos (-1)
196
eede25e7 197class HttpHeaderEntry
198{
199
200public:
eede25e7 201 HttpHeaderEntry(http_hdr_type id, const char *name, const char *value);
202 ~HttpHeaderEntry();
cdce6c61 203 static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
eede25e7 204 HttpHeaderEntry *clone() const;
205 void packInto(Packer *p) const;
206 int getInt() const;
47f6e231 207 int64_t getInt64() const;
eede25e7 208 MEMPROXY_CLASS(HttpHeaderEntry);
209 http_hdr_type id;
30abd221 210 String name;
211 String value;
eede25e7 212};
213
63be0a78 214MEMPROXY_CLASS_INLINE(HttpHeaderEntry);
eede25e7 215
81a94152
AJ
216class ETag;
217class TimeOrTag;
218
924f73bc 219class HttpHeader
220{
221
222public:
75faaa7a 223 HttpHeader();
5e5fa5b1
AR
224 explicit HttpHeader(const http_hdr_owner_type owner);
225 HttpHeader(const HttpHeader &other);
75faaa7a 226 ~HttpHeader();
5e5fa5b1
AR
227
228 HttpHeader &operator =(const HttpHeader &other);
229
924f73bc 230 /* Interface functions */
519e0948 231 void clean();
a9925b40 232 void append(const HttpHeader * src);
233 void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask);
394499bd 234 void compact();
a9925b40 235 int reset();
236 int parse(const char *header_start, const char *header_end);
d8f6c79c 237 void packInto(Packer * p, bool mask_sensitive_info=false) const;
a9925b40 238 HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
239 HttpHeaderEntry *findEntry(http_hdr_type id) const;
240 int delByName(const char *name);
241 int delById(http_hdr_type id);
ba9fb01d 242 void delAt(HttpHeaderPos pos, int &headers_deleted);
243 void refreshMask();
a9925b40 244 void addEntry(HttpHeaderEntry * e);
245 void insertEntry(HttpHeaderEntry * e);
30abd221 246 String getList(http_hdr_type id) const;
247 bool getList(http_hdr_type id, String *s) const;
248 String getStrOrList(http_hdr_type id) const;
249 String getByName(const char *name) const;
250 String getByNameListMember(const char *name, const char *member, const char separator) const;
251 String getListMember(http_hdr_type id, const char *member, const char separator) const;
a9925b40 252 int has(http_hdr_type id) const;
253 void putInt(http_hdr_type id, int number);
47f6e231 254 void putInt64(http_hdr_type id, int64_t number);
a9925b40 255 void putTime(http_hdr_type id, time_t htime);
256 void insertTime(http_hdr_type id, time_t htime);
257 void putStr(http_hdr_type id, const char *str);
258 void putAuth(const char *auth_scheme, const char *realm);
259 void putCc(const HttpHdrCc * cc);
260 void putContRange(const HttpHdrContRange * cr);
261 void putRange(const HttpHdrRange * range);
262 void putSc(HttpHdrSc *sc);
bcfba8bd 263 void putWarning(const int code, const char *const text); ///< add a Warning header
a9925b40 264 void putExt(const char *name, const char *value);
265 int getInt(http_hdr_type id) const;
47f6e231 266 int64_t getInt64(http_hdr_type id) const;
a9925b40 267 time_t getTime(http_hdr_type id) const;
268 const char *getStr(http_hdr_type id) const;
269 const char *getLastStr(http_hdr_type id) const;
270 HttpHdrCc *getCc() const;
271 HttpHdrRange *getRange() const;
272 HttpHdrSc *getSc() const;
273 HttpHdrContRange *getContRange() const;
274 const char *getAuth(http_hdr_type id, const char *auth_scheme) const;
275 ETag getETag(http_hdr_type id) const;
276 TimeOrTag getTimeOrTag(http_hdr_type id) const;
277 int hasListMember(http_hdr_type id, const char *member, const char separator) const;
278 int hasByNameListMember(const char *name, const char *member, const char separator) const;
2cdeea82 279 void removeHopByHopEntries();
c3d0ba0c 280 inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding
63be0a78 281
924f73bc 282 /* protected, do not use these, use interface functions instead */
63be0a78 283 Vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */
284 HttpHeaderMask mask; /**< bit set <=> entry present */
285 http_hdr_owner_type owner; /**< request or reply */
d85b8894 286 int len; /**< length when packed, not counting terminating null-byte */
a9925b40 287
2cdeea82 288protected:
63be0a78 289 /** \deprecated Public access replaced by removeHopByHopEntries() */
2cdeea82 290 void removeConnectionHeaderEntries();
63be0a78 291
a9925b40 292private:
293 HttpHeaderEntry *findLastEntry(http_hdr_type id) const;
924f73bc 294};
528b2c61 295
8a648e8d
FC
296int httpHeaderParseQuotedString(const char *start, const int len, String *val);
297int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
298void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
299void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count);
25b6a907 300
c3d0ba0c
AR
301inline bool
302HttpHeader::chunked() const
303{
304 return has(HDR_TRANSFER_ENCODING) &&
f673997d 305 hasListMember(HDR_TRANSFER_ENCODING, "chunked", ',');
c3d0ba0c
AR
306}
307
8a648e8d
FC
308void httpHeaderInitModule(void);
309void httpHeaderCleanModule(void);
ec6f82c1 310
e6ccf245 311#endif /* SQUID_HTTPHEADER_H */