3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 #ifndef SQUID_HTTPHEADER_H
32 #define SQUID_HTTPHEADER_H
34 /* because we pass a spec by value */
35 #include "HttpHeaderMask.h"
37 #include "SquidString.h"
39 /* class forward declarations */
41 class HttpHdrContRange
;
47 /* constant attributes of http header fields */
49 /// recognized or "known" header fields; and the RFC which defines them (or not)
52 HDR_ACCEPT
= 0, /**< RFC 2608, 2616 */
53 HDR_ACCEPT_CHARSET
, /**< RFC 2608, 2616 */
54 HDR_ACCEPT_ENCODING
, /**< RFC 2608, 2616 */
55 /*HDR_ACCEPT_FEATURES,*/ /* experimental RFC 2295 */
56 HDR_ACCEPT_LANGUAGE
, /**< RFC 2608, 2616 */
57 HDR_ACCEPT_RANGES
, /**< RFC 2608, 2616 */
58 HDR_AGE
, /**< RFC 2608, 2616 */
59 HDR_ALLOW
, /**< RFC 2608, 2616 */
60 /*HDR_ALTERNATES,*/ /* deprecated RFC 2068, 2295 */
61 HDR_AUTHORIZATION
, /**< RFC 2608, 2616, 4559 */
62 HDR_CACHE_CONTROL
, /**< RFC 2608, 2616 */
63 HDR_CONNECTION
, /**< RFC 2608, 2616 */
64 HDR_CONTENT_BASE
, /**< RFC 2608 */
65 HDR_CONTENT_DISPOSITION
, /**< RFC 2183, 2616 */
66 HDR_CONTENT_ENCODING
, /**< RFC 2608, 2616 */
67 HDR_CONTENT_LANGUAGE
, /**< RFC 2608, 2616 */
68 HDR_CONTENT_LENGTH
, /**< RFC 2608, 2616 */
69 HDR_CONTENT_LOCATION
, /**< RFC 2608, 2616 */
70 HDR_CONTENT_MD5
, /**< RFC 2608, 2616 */
71 HDR_CONTENT_RANGE
, /**< RFC 2608, 2616 */
72 HDR_CONTENT_TYPE
, /**< RFC 2608, 2616 */
73 /*HDR_CONTENT_VERSION,*/ /* deprecated RFC 2608 header. */
74 HDR_COOKIE
, /**< de-facto and RFC 2965 header we may need to erase */
75 HDR_COOKIE2
, /**< obsolete RFC 2965 header we may need to erase */
76 HDR_DATE
, /**< RFC 2608, 2616 */
77 /*HDR_DAV,*/ /* RFC 2518 */
78 /*HDR_DEPTH,*/ /* RFC 2518 */
79 /*HDR_DERIVED_FROM,*/ /* deprecated RFC 2608 */
80 /*HDR_DESTINATION,*/ /* RFC 2518 */
81 HDR_ETAG
, /**< RFC 2608, 2616 */
82 HDR_EXPECT
, /**< RFC 2616, 2616 */
83 HDR_EXPIRES
, /**< RFC 2608, 2616 */
84 HDR_FROM
, /**< RFC 2608, 2616 */
85 HDR_HOST
, /**< RFC 2608, 2616 */
86 HDR_HTTP2_SETTINGS
, /**< HTTP/2.0 upgrade header. see draft-ietf-httpbis-http2-04 */
87 /*HDR_IF,*/ /* RFC 2518 */
88 HDR_IF_MATCH
, /**< RFC 2608, 2616 */
89 HDR_IF_MODIFIED_SINCE
, /**< RFC 2608, 2616 */
90 HDR_IF_NONE_MATCH
, /**< RFC 2608, 2616 */
91 HDR_IF_RANGE
, /**< RFC 2608, 2616 */
92 /*HDR_IF_UNMODIFIED_SINCE,*/ /**< RFC 2608, 2616 */
93 HDR_KEEP_ALIVE
, /**< obsolete HTTP/1.0 header we may need to erase */
94 HDR_KEY
, /**< experimental RFC Draft draft-fielding-http-key-02 */
95 HDR_LAST_MODIFIED
, /**< RFC 2608, 2616 */
96 HDR_LINK
, /**< RFC 2068 */
97 HDR_LOCATION
, /**< RFC 2608, 2616 */
98 /*HDR_LOCK_TOKEN,*/ /* RFC 2518 */
99 HDR_MAX_FORWARDS
, /**< RFC 2608, 2616 */
100 HDR_MIME_VERSION
, /**< RFC 2626 */
101 HDR_NEGOTIATE
, /**< experimental RFC 2295. Why only this one from 2295? */
102 /*HDR_OVERWRITE,*/ /* RFC 2518 */
103 HDR_ORIGIN
, /* CORS Draft specification (see http://www.w3.org/TR/cors/) */
104 HDR_PRAGMA
, /**< deprecated RFC 2068,2616 header we may need to erase */
105 HDR_PROXY_AUTHENTICATE
, /**< RFC 2608, 2616, 2617 */
106 HDR_PROXY_AUTHENTICATION_INFO
, /**< RFC 2617 */
107 HDR_PROXY_AUTHORIZATION
, /**< RFC 2608, 2616, 2617 */
108 HDR_PROXY_CONNECTION
, /**< obsolete Netscape header we may need to erase. */
109 HDR_PROXY_SUPPORT
, /**< RFC 4559 */
110 HDR_PUBLIC
, /**< RFC 2608 */
111 HDR_RANGE
, /**< RFC 2608, 2616 */
112 HDR_REFERER
, /**< RFC 2608, 2616 */
113 HDR_REQUEST_RANGE
, /**< some clients use this, sigh */
114 HDR_RETRY_AFTER
, /**< RFC 2608, 2616 */
115 HDR_SERVER
, /**< RFC 2608, 2616 */
116 HDR_SET_COOKIE
, /**< de-facto standard header we may need to erase */
117 HDR_SET_COOKIE2
, /**< obsolete RFC 2965 header we may need to erase */
118 /*HDR_STATUS_URI,*/ /* RFC 2518 */
119 /*HDR_TCN,*/ /* experimental RFC 2295 */
120 HDR_TE
, /**< RFC 2616 */
121 /*HDR_TIMEOUT,*/ /* RFC 2518 */
122 HDR_TITLE
, /* obsolete draft suggested header */
123 HDR_TRAILER
, /**< RFC 2616 */
124 HDR_TRANSFER_ENCODING
, /**< RFC 2608, 2616 */
125 HDR_TRANSLATE
, /**< IIS custom header we may need to erase */
126 HDR_UNLESS_MODIFIED_SINCE
, /**< IIS custom header we may need to erase */
127 HDR_UPGRADE
, /**< RFC 2608, 2616 */
128 /*HDR_URI,*/ /* obsolete RFC 2068 header */
129 HDR_USER_AGENT
, /**< RFC 2608, 2616 */
130 /*HDR_VARIANT_VARY,*/ /* experimental RFC 2295 */
131 HDR_VARY
, /**< RFC 2608, 2616 */
132 HDR_VIA
, /**< RFC 2608, 2616 */
133 HDR_WARNING
, /**< RFC 2608, 2616 */
134 HDR_WWW_AUTHENTICATE
, /**< RFC 2608, 2616, 2617, 4559 */
135 HDR_AUTHENTICATION_INFO
, /**< RFC 2617 */
136 HDR_X_CACHE
, /**< Squid custom header */
137 HDR_X_CACHE_LOOKUP
, /**< Squid custom header. temporary hack that became de-facto. TODO remove */
138 HDR_X_FORWARDED_FOR
, /**< Squid custom header */
139 HDR_X_REQUEST_URI
, /**< Squid custom header appended if ADD_X_REQUEST_URI is defined */
140 HDR_X_SQUID_ERROR
, /**< Squid custom header on generated error responses */
141 #if X_ACCELERATOR_VARY
142 HDR_X_ACCELERATOR_VARY
, /**< obsolete Squid custom header. */
145 HDR_X_NEXT_SERVICES
, /**< Squid custom ICAP header */
147 HDR_SURROGATE_CAPABILITY
, /**< Edge Side Includes (ESI) header */
148 HDR_SURROGATE_CONTROL
, /**< Edge Side Includes (ESI) header */
149 HDR_FRONT_END_HTTPS
, /**< MS Exchange custom header we may have to add */
150 HDR_OTHER
, /**< internal tag value for "unknown" headers */
154 /** possible types for http header fields */
156 ftInvalid
= HDR_ENUM_END
, /**< to catch nasty errors with hdr_id<->fld_type clashes */
169 /** Possible owners of http header */
181 } http_hdr_owner_type
;
184 class HttpHeaderFieldAttrs
192 /** Iteration for headers; use HttpHeaderPos as opaque type, do not interpret */
193 typedef ssize_t HttpHeaderPos
;
195 /* use this and only this to initialize HttpHeaderPos */
196 #define HttpHeaderInitPos (-1)
198 class HttpHeaderEntry
202 HttpHeaderEntry(http_hdr_type id
, const char *name
, const char *value
);
204 static HttpHeaderEntry
*parse(const char *field_start
, const char *field_end
);
205 HttpHeaderEntry
*clone() const;
206 void packInto(Packer
*p
) const;
208 int64_t getInt64() const;
209 MEMPROXY_CLASS(HttpHeaderEntry
);
215 MEMPROXY_CLASS_INLINE(HttpHeaderEntry
);
225 explicit HttpHeader(const http_hdr_owner_type owner
);
226 HttpHeader(const HttpHeader
&other
);
229 HttpHeader
&operator =(const HttpHeader
&other
);
231 /* Interface functions */
233 void append(const HttpHeader
* src
);
234 void update (HttpHeader
const *fresh
, HttpHeaderMask
const *denied_mask
);
237 int parse(const char *header_start
, const char *header_end
);
238 void packInto(Packer
* p
, bool mask_sensitive_info
=false) const;
239 HttpHeaderEntry
*getEntry(HttpHeaderPos
* pos
) const;
240 HttpHeaderEntry
*findEntry(http_hdr_type id
) const;
241 int delByName(const char *name
);
242 int delById(http_hdr_type id
);
243 void delAt(HttpHeaderPos pos
, int &headers_deleted
);
245 void addEntry(HttpHeaderEntry
* e
);
246 void insertEntry(HttpHeaderEntry
* e
);
247 String
getList(http_hdr_type id
) const;
248 bool getList(http_hdr_type id
, String
*s
) const;
249 String
getStrOrList(http_hdr_type id
) const;
250 String
getByName(const char *name
) const;
251 /// sets value and returns true iff a [possibly empty] named field is there
252 bool getByNameIfPresent(const char *name
, String
&value
) const;
253 String
getByNameListMember(const char *name
, const char *member
, const char separator
) const;
254 String
getListMember(http_hdr_type id
, const char *member
, const char separator
) const;
255 int has(http_hdr_type id
) const;
256 void putInt(http_hdr_type id
, int number
);
257 void putInt64(http_hdr_type id
, int64_t number
);
258 void putTime(http_hdr_type id
, time_t htime
);
259 void insertTime(http_hdr_type id
, time_t htime
);
260 void putStr(http_hdr_type id
, const char *str
);
261 void putAuth(const char *auth_scheme
, const char *realm
);
262 void putCc(const HttpHdrCc
* cc
);
263 void putContRange(const HttpHdrContRange
* cr
);
264 void putRange(const HttpHdrRange
* range
);
265 void putSc(HttpHdrSc
*sc
);
266 void putWarning(const int code
, const char *const text
); ///< add a Warning header
267 void putExt(const char *name
, const char *value
);
268 int getInt(http_hdr_type id
) const;
269 int64_t getInt64(http_hdr_type id
) const;
270 time_t getTime(http_hdr_type id
) const;
271 const char *getStr(http_hdr_type id
) const;
272 const char *getLastStr(http_hdr_type id
) const;
273 HttpHdrCc
*getCc() const;
274 HttpHdrRange
*getRange() const;
275 HttpHdrSc
*getSc() const;
276 HttpHdrContRange
*getContRange() const;
277 const char *getAuth(http_hdr_type id
, const char *auth_scheme
) const;
278 ETag
getETag(http_hdr_type id
) const;
279 TimeOrTag
getTimeOrTag(http_hdr_type id
) const;
280 int hasListMember(http_hdr_type id
, const char *member
, const char separator
) const;
281 int hasByNameListMember(const char *name
, const char *member
, const char separator
) const;
282 void removeHopByHopEntries();
283 inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding
285 /* protected, do not use these, use interface functions instead */
286 Vector
<HttpHeaderEntry
*> entries
; /**< parsed fields in raw format */
287 HttpHeaderMask mask
; /**< bit set <=> entry present */
288 http_hdr_owner_type owner
; /**< request or reply */
289 int len
; /**< length when packed, not counting terminating null-byte */
292 /** \deprecated Public access replaced by removeHopByHopEntries() */
293 void removeConnectionHeaderEntries();
296 HttpHeaderEntry
*findLastEntry(http_hdr_type id
) const;
299 int httpHeaderParseQuotedString(const char *start
, const int len
, String
*val
);
300 int httpHeaderHasByNameListMember(const HttpHeader
* hdr
, const char *name
, const char *member
, const char separator
);
301 void httpHeaderUpdate(HttpHeader
* old
, const HttpHeader
* fresh
, const HttpHeaderMask
* denied_mask
);
302 void httpHeaderCalcMask(HttpHeaderMask
* mask
, http_hdr_type http_hdr_type_enums
[], size_t count
);
305 HttpHeader::chunked() const
307 return has(HDR_TRANSFER_ENCODING
) &&
308 hasListMember(HDR_TRANSFER_ENCODING
, "chunked", ',');
311 void httpHeaderInitModule(void);
312 void httpHeaderCleanModule(void);
314 #endif /* SQUID_HTTPHEADER_H */