3 * $Id: HttpHeader.h,v 1.23 2007/08/13 17:20:51 hno 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
);
206 int parse(const char *header_start
, const char *header_end
);
207 void packInto(Packer
* p
) const;
208 HttpHeaderEntry
*getEntry(HttpHeaderPos
* pos
) const;
209 HttpHeaderEntry
*findEntry(http_hdr_type id
) const;
210 int delByName(const char *name
);
211 int delById(http_hdr_type id
);
212 void delAt(HttpHeaderPos pos
, int &headers_deleted
);
214 void addEntry(HttpHeaderEntry
* e
);
215 void insertEntry(HttpHeaderEntry
* e
);
216 String
getList(http_hdr_type id
) const;
217 bool getList(http_hdr_type id
, String
*s
) const;
218 String
getStrOrList(http_hdr_type id
) const;
219 String
getByName(const char *name
) const;
220 String
getByNameListMember(const char *name
, const char *member
, const char separator
) const;
221 String
getListMember(http_hdr_type id
, const char *member
, const char separator
) const;
222 int has(http_hdr_type id
) const;
223 void putInt(http_hdr_type id
, int number
);
224 void putInt64(http_hdr_type id
, int64_t number
);
225 void putTime(http_hdr_type id
, time_t htime
);
226 void insertTime(http_hdr_type id
, time_t htime
);
227 void putStr(http_hdr_type id
, const char *str
);
228 void putAuth(const char *auth_scheme
, const char *realm
);
229 void putCc(const HttpHdrCc
* cc
);
230 void putContRange(const HttpHdrContRange
* cr
);
231 void putRange(const HttpHdrRange
* range
);
232 void putSc(HttpHdrSc
*sc
);
233 void putExt(const char *name
, const char *value
);
234 int getInt(http_hdr_type id
) const;
235 int64_t getInt64(http_hdr_type id
) const;
236 time_t getTime(http_hdr_type id
) const;
237 const char *getStr(http_hdr_type id
) const;
238 const char *getLastStr(http_hdr_type id
) const;
239 HttpHdrCc
*getCc() const;
240 HttpHdrRange
*getRange() const;
241 HttpHdrSc
*getSc() const;
242 HttpHdrContRange
*getContRange() const;
243 const char *getAuth(http_hdr_type id
, const char *auth_scheme
) const;
244 ETag
getETag(http_hdr_type id
) const;
245 TimeOrTag
getTimeOrTag(http_hdr_type id
) const;
246 int hasListMember(http_hdr_type id
, const char *member
, const char separator
) const;
247 int hasByNameListMember(const char *name
, const char *member
, const char separator
) const;
248 void removeConnectionHeaderEntries();
249 /* protected, do not use these, use interface functions instead */
250 Vector
<HttpHeaderEntry
*> entries
; /* parsed fields in raw format */
251 HttpHeaderMask mask
; /* bit set <=> entry present */
252 http_hdr_owner_type owner
; /* request or reply */
253 int len
; /* length when packed, not counting terminating '\0' */
256 HttpHeaderEntry
*findLastEntry(http_hdr_type id
) const;
257 // Make it non-copyable. Our destructor is a bit nasty...
258 HttpHeader(const HttpHeader
&);
259 //assignment is used by the reset method, can't block it..
260 //const HttpHeader operator=(const HttpHeader &);
264 extern void httpHeaderRegisterWithCacheManager(CacheManager
& manager
);
265 extern int httpHeaderParseQuotedString (const char *start
, String
*val
);
266 SQUIDCEXTERN
int httpHeaderHasByNameListMember(const HttpHeader
* hdr
, const char *name
, const char *member
, const char separator
);
267 SQUIDCEXTERN
void httpHeaderUpdate(HttpHeader
* old
, const HttpHeader
* fresh
, const HttpHeaderMask
* denied_mask
);
268 int httpMsgIsPersistent(HttpVersion
const &http_ver
, const HttpHeader
* hdr
);
270 SQUIDCEXTERN
void httpHeaderCalcMask(HttpHeaderMask
* mask
, http_hdr_type http_hdr_type_enums
[], size_t count
);
272 #endif /* SQUID_HTTPHEADER_H */