]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHeader.h
Bug 1923 fix: Do not send hop-by-hop headers to the ICAP server.
[thirdparty/squid.git] / src / HttpHeader.h
1
2 /*
3 * $Id: HttpHeader.h,v 1.25 2008/01/22 19:53:03 rousskov Exp $
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
37 /* forward decls */
38
39 class CacheManager;
40 /* because we pass a spec by value */
41 #include "HttpHeaderRange.h"
42 /* HttpHeader holds a HttpHeaderMask */
43 #include "HttpHeaderMask.h"
44
45 /* constant attributes of http header fields */
46
47 /* recognized or "known" header fields; @?@ add more! */
48 typedef 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,
78 HDR_KEEP_ALIVE,
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,
96 HDR_TE,
97 HDR_TITLE,
98 HDR_TRAILERS,
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 */
124 typedef enum {
125 ftInvalid = HDR_ENUM_END, /* to catch nasty errors with hdr_id<->fld_type clashes */
126 ftInt,
127 ftInt64,
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 */
139 typedef enum {
140 hoNone =0,
141 #if USE_HTCP
142 hoHtcpReply,
143 #endif
144 hoRequest,
145 hoReply
146 } http_hdr_owner_type;
147
148 struct _HttpHeaderFieldAttrs
149 {
150 const char *name;
151 http_hdr_type id;
152 field_type type;
153 };
154
155 class HttpVersion;
156
157 class HttpHdrContRange;
158
159 class HttpHdrCc;
160
161 class HttpHdrSc;
162
163 /*iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
164 typedef 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
171 typedef struct _TimeOrTag TimeOrTag;
172
173 typedef struct _ETag ETag;
174
175 class HttpHeaderEntry
176 {
177
178 public:
179 HttpHeaderEntry(http_hdr_type id, const char *name, const char *value);
180 ~HttpHeaderEntry();
181 static HttpHeaderEntry *parse(const char *field_start, const char *field_end);
182 HttpHeaderEntry *clone() const;
183 void packInto(Packer *p) const;
184 int getInt() const;
185 int64_t getInt64() const;
186 MEMPROXY_CLASS(HttpHeaderEntry);
187 http_hdr_type id;
188 String name;
189 String value;
190 };
191
192 MEMPROXY_CLASS_INLINE(HttpHeaderEntry)
193
194 class HttpHeader
195 {
196
197 public:
198 HttpHeader();
199 HttpHeader(http_hdr_owner_type const &owner);
200 ~HttpHeader();
201 /* Interface functions */
202 void clean();
203 void append(const HttpHeader * src);
204 void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask);
205 void compact();
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);
213 void delAt(HttpHeaderPos pos, int &headers_deleted);
214 void refreshMask();
215 void addEntry(HttpHeaderEntry * e);
216 void insertEntry(HttpHeaderEntry * e);
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;
223 int has(http_hdr_type id) const;
224 void putInt(http_hdr_type id, int number);
225 void putInt64(http_hdr_type id, int64_t number);
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;
236 int64_t getInt64(http_hdr_type id) const;
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;
249 void removeHopByHopEntries();
250 /* protected, do not use these, use interface functions instead */
251 Vector<HttpHeaderEntry *> entries; /* parsed fields in raw format */
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' */
255
256 protected:
257 void removeConnectionHeaderEntries();
258
259 private:
260 HttpHeaderEntry *findLastEntry(http_hdr_type id) const;
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 &);
265 };
266
267
268 extern void httpHeaderRegisterWithCacheManager(CacheManager & manager);
269 extern int httpHeaderParseQuotedString (const char *start, String *val);
270 SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator);
271 SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);
272 int httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr);
273
274 SQUIDCEXTERN void httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count);
275
276 #endif /* SQUID_HTTPHEADER_H */