]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHeader.h
Replaced custom letterhead with an XXX note about source code origin.
[thirdparty/squid.git] / src / HttpHeader.h
CommitLineData
e6ccf245 1
2/*
2cdeea82 3 * $Id: HttpHeader.h,v 1.25 2008/01/22 19:53:03 rousskov Exp $
e6ccf245 4 *
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33
34#ifndef SQUID_HTTPHEADER_H
35#define SQUID_HTTPHEADER_H
36
62ee09ca 37/* forward decls */
38
39class CacheManager;
528b2c61 40/* because we pass a spec by value */
41#include "HttpHeaderRange.h"
25b6a907 42/* HttpHeader holds a HttpHeaderMask */
43#include "HttpHeaderMask.h"
e6ccf245 44
45/* constant attributes of http header fields */
62e76326 46
25b6a907 47/* recognized or "known" header fields; @?@ add more! */
48typedef enum {
49 HDR_BAD_HDR = -1,
50 HDR_ACCEPT = 0,
51 HDR_ACCEPT_CHARSET,
52 HDR_ACCEPT_ENCODING,
53 HDR_ACCEPT_LANGUAGE,
54 HDR_ACCEPT_RANGES,
55 HDR_AGE,
56 HDR_ALLOW,
57 HDR_AUTHORIZATION,
58 HDR_CACHE_CONTROL,
59 HDR_CONNECTION,
60 HDR_CONTENT_BASE,
61 HDR_CONTENT_ENCODING,
62 HDR_CONTENT_LANGUAGE,
63 HDR_CONTENT_LENGTH,
64 HDR_CONTENT_LOCATION,
65 HDR_CONTENT_MD5,
66 HDR_CONTENT_RANGE,
67 HDR_CONTENT_TYPE,
68 HDR_COOKIE,
69 HDR_DATE,
70 HDR_ETAG,
71 HDR_EXPIRES,
72 HDR_FROM,
73 HDR_HOST,
74 HDR_IF_MATCH,
75 HDR_IF_MODIFIED_SINCE,
76 HDR_IF_NONE_MATCH,
77 HDR_IF_RANGE,
1d7ab0f4 78 HDR_KEEP_ALIVE,
25b6a907 79 HDR_LAST_MODIFIED,
80 HDR_LINK,
81 HDR_LOCATION,
82 HDR_MAX_FORWARDS,
83 HDR_MIME_VERSION,
84 HDR_PRAGMA,
85 HDR_PROXY_AUTHENTICATE,
86 HDR_PROXY_AUTHENTICATION_INFO,
87 HDR_PROXY_AUTHORIZATION,
88 HDR_PROXY_CONNECTION,
89 HDR_PUBLIC,
90 HDR_RANGE,
91 HDR_REQUEST_RANGE, /* some clients use this, sigh */
92 HDR_REFERER,
93 HDR_RETRY_AFTER,
94 HDR_SERVER,
95 HDR_SET_COOKIE,
1d7ab0f4 96 HDR_TE,
25b6a907 97 HDR_TITLE,
1d7ab0f4 98 HDR_TRAILERS,
25b6a907 99 HDR_TRANSFER_ENCODING,
100 HDR_UPGRADE,
101 HDR_USER_AGENT,
102 HDR_VARY,
103 HDR_VIA,
104 HDR_WARNING,
105 HDR_WWW_AUTHENTICATE,
106 HDR_AUTHENTICATION_INFO,
107 HDR_X_CACHE,
108 HDR_X_CACHE_LOOKUP, /* tmp hack, remove later */
109 HDR_X_FORWARDED_FOR,
110 HDR_X_REQUEST_URI, /* appended if ADD_X_REQUEST_URI is #defined */
111 HDR_X_SQUID_ERROR,
112 HDR_NEGOTIATE,
113#if X_ACCELERATOR_VARY
114 HDR_X_ACCELERATOR_VARY,
115#endif
116 HDR_SURROGATE_CAPABILITY,
117 HDR_SURROGATE_CONTROL,
118 HDR_FRONT_END_HTTPS,
119 HDR_OTHER,
120 HDR_ENUM_END
121} http_hdr_type;
122
123/* possible types for http header fields */
124typedef enum {
125 ftInvalid = HDR_ENUM_END, /* to catch nasty errors with hdr_id<->fld_type clashes */
126 ftInt,
47f6e231 127 ftInt64,
25b6a907 128 ftStr,
129 ftDate_1123,
130 ftETag,
131 ftPCc,
132 ftPContRange,
133 ftPRange,
134 ftPSc,
135 ftDate_1123_or_ETag
136} field_type;
137
138/* possible owners of http header */
139typedef enum {
0b57cb3d 140 hoNone =0,
25b6a907 141#if USE_HTCP
142 hoHtcpReply,
143#endif
144 hoRequest,
145 hoReply
146} http_hdr_owner_type;
147
62e76326 148struct _HttpHeaderFieldAttrs
149{
e6ccf245 150 const char *name;
151 http_hdr_type id;
152 field_type type;
153};
154
450e0c10 155class HttpVersion;
156
a9925b40 157class HttpHdrContRange;
158
985c86bc 159class HttpHdrCc;
160
a9925b40 161class HttpHdrSc;
162
985c86bc 163/*iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
164typedef ssize_t HttpHeaderPos;
165
166/* use this and only this to initialize HttpHeaderPos */
167#define HttpHeaderInitPos (-1)
168
169/* these two are defined in structs.h */
170
171typedef struct _TimeOrTag TimeOrTag;
172
173typedef struct _ETag ETag;
174
eede25e7 175class HttpHeaderEntry
176{
177
178public:
eede25e7 179 HttpHeaderEntry(http_hdr_type id, const char *name, const char *value);
180 ~HttpHeaderEntry();
cdce6c61 181 static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
eede25e7 182 HttpHeaderEntry *clone() const;
183 void packInto(Packer *p) const;
184 int getInt() const;
47f6e231 185 int64_t getInt64() const;
eede25e7 186 MEMPROXY_CLASS(HttpHeaderEntry);
187 http_hdr_type id;
30abd221 188 String name;
189 String value;
eede25e7 190};
191
192MEMPROXY_CLASS_INLINE(HttpHeaderEntry)
193
924f73bc 194class HttpHeader
195{
196
197public:
75faaa7a 198 HttpHeader();
199 HttpHeader(http_hdr_owner_type const &owner);
200 ~HttpHeader();
924f73bc 201 /* Interface functions */
519e0948 202 void clean();
a9925b40 203 void append(const HttpHeader * src);
204 void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask);
394499bd 205 void compact();
a9925b40 206 int reset();
207 int parse(const char *header_start, const char *header_end);
208 void packInto(Packer * p) const;
209 HttpHeaderEntry *getEntry(HttpHeaderPos * pos) const;
210 HttpHeaderEntry *findEntry(http_hdr_type id) const;
211 int delByName(const char *name);
212 int delById(http_hdr_type id);
ba9fb01d 213 void delAt(HttpHeaderPos pos, int &headers_deleted);
214 void refreshMask();
a9925b40 215 void addEntry(HttpHeaderEntry * e);
216 void insertEntry(HttpHeaderEntry * e);
30abd221 217 String getList(http_hdr_type id) const;
218 bool getList(http_hdr_type id, String *s) const;
219 String getStrOrList(http_hdr_type id) const;
220 String getByName(const char *name) const;
221 String getByNameListMember(const char *name, const char *member, const char separator) const;
222 String getListMember(http_hdr_type id, const char *member, const char separator) const;
a9925b40 223 int has(http_hdr_type id) const;
224 void putInt(http_hdr_type id, int number);
47f6e231 225 void putInt64(http_hdr_type id, int64_t number);
a9925b40 226 void putTime(http_hdr_type id, time_t htime);
227 void insertTime(http_hdr_type id, time_t htime);
228 void putStr(http_hdr_type id, const char *str);
229 void putAuth(const char *auth_scheme, const char *realm);
230 void putCc(const HttpHdrCc * cc);
231 void putContRange(const HttpHdrContRange * cr);
232 void putRange(const HttpHdrRange * range);
233 void putSc(HttpHdrSc *sc);
234 void putExt(const char *name, const char *value);
235 int getInt(http_hdr_type id) const;
47f6e231 236 int64_t getInt64(http_hdr_type id) const;
a9925b40 237 time_t getTime(http_hdr_type id) const;
238 const char *getStr(http_hdr_type id) const;
239 const char *getLastStr(http_hdr_type id) const;
240 HttpHdrCc *getCc() const;
241 HttpHdrRange *getRange() const;
242 HttpHdrSc *getSc() const;
243 HttpHdrContRange *getContRange() const;
244 const char *getAuth(http_hdr_type id, const char *auth_scheme) const;
245 ETag getETag(http_hdr_type id) const;
246 TimeOrTag getTimeOrTag(http_hdr_type id) const;
247 int hasListMember(http_hdr_type id, const char *member, const char separator) const;
248 int hasByNameListMember(const char *name, const char *member, const char separator) const;
2cdeea82 249 void removeHopByHopEntries();
924f73bc 250 /* protected, do not use these, use interface functions instead */
75faaa7a 251 Vector<HttpHeaderEntry *> entries; /* parsed fields in raw format */
924f73bc 252 HttpHeaderMask mask; /* bit set <=> entry present */
253 http_hdr_owner_type owner; /* request or reply */
254 int len; /* length when packed, not counting terminating '\0' */
a9925b40 255
2cdeea82 256protected:
257 void removeConnectionHeaderEntries();
258
a9925b40 259private:
260 HttpHeaderEntry *findLastEntry(http_hdr_type id) const;
6e26baea 261 // Make it non-copyable. Our destructor is a bit nasty...
262 HttpHeader(const HttpHeader &);
263 //assignment is used by the reset method, can't block it..
264 //const HttpHeader operator=(const HttpHeader &);
924f73bc 265};
528b2c61 266
62ee09ca 267
268extern void httpHeaderRegisterWithCacheManager(CacheManager & manager);
30abd221 269extern int httpHeaderParseQuotedString (const char *start, String *val);
25b6a907 270SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
271SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
272int httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr);
273
274SQUIDCEXTERN void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count);
275
e6ccf245 276#endif /* SQUID_HTTPHEADER_H */