3 * $Id: HttpHeader.h,v 1.25 2008/01/22 19:53:03 rousskov Exp $
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
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.
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.
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.
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.
34 #ifndef SQUID_HTTPHEADER_H
35 #define SQUID_HTTPHEADER_H
40 /* because we pass a spec by value */
41 #include "HttpHeaderRange.h"
42 /* HttpHeader holds a HttpHeaderMask */
43 #include "HttpHeaderMask.h"
45 /* constant attributes of http header fields */
47 /* recognized or "known" header fields; @?@ add more! */
75 HDR_IF_MODIFIED_SINCE
,
85 HDR_PROXY_AUTHENTICATE
,
86 HDR_PROXY_AUTHENTICATION_INFO
,
87 HDR_PROXY_AUTHORIZATION
,
91 HDR_REQUEST_RANGE
, /* some clients use this, sigh */
99 HDR_TRANSFER_ENCODING
,
105 HDR_WWW_AUTHENTICATE
,
106 HDR_AUTHENTICATION_INFO
,
108 HDR_X_CACHE_LOOKUP
, /* tmp hack, remove later */
110 HDR_X_REQUEST_URI
, /* appended if ADD_X_REQUEST_URI is #defined */
113 #if X_ACCELERATOR_VARY
114 HDR_X_ACCELERATOR_VARY
,
116 HDR_SURROGATE_CAPABILITY
,
117 HDR_SURROGATE_CONTROL
,
123 /* possible types for http header fields */
125 ftInvalid
= HDR_ENUM_END
, /* to catch nasty errors with hdr_id<->fld_type clashes */
138 /* possible owners of http header */
146 } http_hdr_owner_type
;
148 struct _HttpHeaderFieldAttrs
157 class HttpHdrContRange
;
163 /*iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
164 typedef ssize_t HttpHeaderPos
;
166 /* use this and only this to initialize HttpHeaderPos */
167 #define HttpHeaderInitPos (-1)
169 /* these two are defined in structs.h */
171 typedef struct _TimeOrTag TimeOrTag
;
173 typedef struct _ETag ETag
;
175 class HttpHeaderEntry
179 HttpHeaderEntry(http_hdr_type id
, const char *name
, const char *value
);
181 static HttpHeaderEntry
*parse(const char *field_start
, const char *field_end
);
182 HttpHeaderEntry
*clone() const;
183 void packInto(Packer
*p
) const;
185 int64_t getInt64() const;
186 MEMPROXY_CLASS(HttpHeaderEntry
);
192 MEMPROXY_CLASS_INLINE(HttpHeaderEntry
)
199 HttpHeader(http_hdr_owner_type
const &owner
);
201 /* Interface functions */
203 void append(const HttpHeader
* src
);
204 void update (HttpHeader
const *fresh
, HttpHeaderMask
const *denied_mask
);
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
);
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' */
257 void removeConnectionHeaderEntries();
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 &);
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
);
274 SQUIDCEXTERN
void httpHeaderCalcMask(HttpHeaderMask
* mask
, http_hdr_type http_hdr_type_enums
[], size_t count
);
276 #endif /* SQUID_HTTPHEADER_H */