5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 #ifndef SQUID_HTTPHEADER_H
34 #define SQUID_HTTPHEADER_H
37 /* because we pass a spec by value */
38 #include "HttpHeaderRange.h"
39 /* HttpHeader holds a HttpHeaderMask */
40 #include "HttpHeaderMask.h"
42 /* constant attributes of http header fields */
44 /** recognized or "known" header fields; @?@ add more! */
72 HDR_IF_MODIFIED_SINCE
,
82 HDR_PROXY_AUTHENTICATE
,
83 HDR_PROXY_AUTHENTICATION_INFO
,
84 HDR_PROXY_AUTHORIZATION
,
89 HDR_REQUEST_RANGE
, /**< some clients use this, sigh */
97 HDR_TRANSFER_ENCODING
,
103 HDR_WWW_AUTHENTICATE
,
104 HDR_AUTHENTICATION_INFO
,
106 HDR_X_CACHE_LOOKUP
, /**< tmp hack, remove later */
108 HDR_X_REQUEST_URI
, /**< appended if ADD_X_REQUEST_URI is #defined */
111 #if X_ACCELERATOR_VARY
112 HDR_X_ACCELERATOR_VARY
,
114 HDR_SURROGATE_CAPABILITY
,
115 HDR_SURROGATE_CONTROL
,
121 /** possible types for http header fields */
123 ftInvalid
= HDR_ENUM_END
, /**< to catch nasty errors with hdr_id<->fld_type clashes */
136 /** Possible owners of http header */
144 } http_hdr_owner_type
;
146 struct _HttpHeaderFieldAttrs
{
154 class HttpHdrContRange
;
160 /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
161 typedef ssize_t HttpHeaderPos
;
163 /* use this and only this to initialize HttpHeaderPos */
164 #define HttpHeaderInitPos (-1)
166 /* these two are defined in structs.h */
168 /// \todo CLEANUP: Kill this.
169 typedef struct _TimeOrTag TimeOrTag
;
171 /// \todo CLEANUP: Kill this.
172 typedef struct _ETag ETag
;
174 class HttpHeaderEntry
178 HttpHeaderEntry(http_hdr_type id
, const char *name
, const char *value
);
180 static HttpHeaderEntry
*parse(const char *field_start
, const char *field_end
);
181 HttpHeaderEntry
*clone() const;
182 void packInto(Packer
*p
) const;
184 int64_t getInt64() const;
185 MEMPROXY_CLASS(HttpHeaderEntry
);
191 MEMPROXY_CLASS_INLINE(HttpHeaderEntry
);
198 HttpHeader(http_hdr_owner_type
const &owner
);
200 /* Interface functions */
202 void append(const HttpHeader
* src
);
203 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 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 /** \deprecated Public access replaced by removeHopByHopEntries() */
258 void removeConnectionHeaderEntries();
261 HttpHeaderEntry
*findLastEntry(http_hdr_type id
) const;
262 /// Made it non-copyable. Our destructor is a bit nasty...
263 HttpHeader(const HttpHeader
&);
264 //assignment is used by the reset method, can't block it..
265 //const HttpHeader operator=(const HttpHeader &);
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 */