]>
Commit | Line | Data |
---|---|---|
7faf2bdb | 1 | /* |
7faf2bdb | 2 | * DEBUG: section 66 HTTP Header Tools |
3 | * AUTHOR: Alex Rousskov | |
4 | * | |
2b6662ba | 5 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 6 | * ---------------------------------------------------------- |
7faf2bdb | 7 | * |
2b6662ba | 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. | |
7faf2bdb | 16 | * |
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. | |
26ac0430 | 21 | * |
7faf2bdb | 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. | |
26ac0430 | 26 | * |
7faf2bdb | 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 | |
cbdec147 | 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 30 | * |
7faf2bdb | 31 | */ |
32 | ||
582c2af2 | 33 | #include "squid.h" |
c0941a6a | 34 | #include "acl/FilledChecklist.h" |
3b07476b | 35 | #include "acl/Gadgets.h" |
f4698e0b | 36 | #include "client_side_request.h" |
582c2af2 | 37 | #include "client_side.h" |
f4698e0b | 38 | #include "comm/Connection.h" |
27bc2077 | 39 | #include "compat/strtoll.h" |
f4698e0b | 40 | #include "fde.h" |
27bc2077 AJ |
41 | #include "HttpHdrContRange.h" |
42 | #include "HttpHeader.h" | |
79cb238d | 43 | #include "HttpHeaderFieldInfo.h" |
3b07476b CT |
44 | #include "HttpHeaderTools.h" |
45 | #include "HttpRequest.h" | |
0eb49b6d | 46 | #include "MemBuf.h" |
4d5904f7 | 47 | #include "SquidConfig.h" |
582c2af2 | 48 | #include "Store.h" |
28204b3b | 49 | #include "StrList.h" |
582c2af2 | 50 | |
f4698e0b CT |
51 | #if USE_SSL |
52 | #include "ssl/support.h" | |
53 | #endif | |
582c2af2 | 54 | |
f4698e0b | 55 | #include <algorithm> |
f4698e0b | 56 | #include <string> |
21d845b1 FC |
57 | #if HAVE_ERRNO_H |
58 | #include <errno.h> | |
59 | #endif | |
7faf2bdb | 60 | |
2246b732 | 61 | static void httpHeaderPutStrvf(HttpHeader * hdr, http_hdr_type id, const char *fmt, va_list vargs); |
de336bbe | 62 | |
de336bbe | 63 | HttpHeaderFieldInfo * |
b644367b | 64 | httpHeaderBuildFieldsInfo(const HttpHeaderFieldAttrs * attrs, int count) |
7faf2bdb | 65 | { |
66 | int i; | |
de336bbe | 67 | HttpHeaderFieldInfo *table = NULL; |
68 | assert(attrs && count); | |
69 | ||
70 | /* allocate space */ | |
0353e724 | 71 | table = new HttpHeaderFieldInfo[count]; |
7faf2bdb | 72 | |
7faf2bdb | 73 | for (i = 0; i < count; ++i) { |
62e76326 | 74 | const http_hdr_type id = attrs[i].id; |
75 | HttpHeaderFieldInfo *info = table + id; | |
76 | /* sanity checks */ | |
77 | assert(id >= 0 && id < count); | |
78 | assert(attrs[i].name); | |
0353e724 | 79 | assert(info->id == HDR_ACCEPT && info->type == ftInvalid); /* was not set before */ |
62e76326 | 80 | /* copy and init fields */ |
81 | info->id = id; | |
82 | info->type = attrs[i].type; | |
83 | info->name = attrs[i].name; | |
84 | assert(info->name.size()); | |
7faf2bdb | 85 | } |
62e76326 | 86 | |
de336bbe | 87 | return table; |
88 | } | |
89 | ||
90 | void | |
b644367b | 91 | httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * table, int count) |
de336bbe | 92 | { |
93 | int i; | |
62e76326 | 94 | |
de336bbe | 95 | for (i = 0; i < count; ++i) |
30abd221 | 96 | table[i].name.clean(); |
62e76326 | 97 | |
7f4c8dec | 98 | delete [] table; |
7faf2bdb | 99 | } |
100 | ||
d8b249ef | 101 | void |
97474590 | 102 | httpHeaderMaskInit(HttpHeaderMask * mask, int value) |
d8b249ef | 103 | { |
97474590 | 104 | memset(mask, value, sizeof(*mask)); |
d8b249ef | 105 | } |
106 | ||
b50e327b | 107 | /** calculates a bit mask of a given array; does not reset mask! */ |
d8b249ef | 108 | void |
8abf232c | 109 | httpHeaderCalcMask(HttpHeaderMask * mask, http_hdr_type http_hdr_type_enums[], size_t count) |
7faf2bdb | 110 | { |
e6ccf245 | 111 | size_t i; |
8abf232c | 112 | const int * enums = (const int *) http_hdr_type_enums; |
d8b249ef | 113 | assert(mask && enums); |
99edd1c3 | 114 | assert(count < sizeof(*mask) * 8); /* check for overflow */ |
7faf2bdb | 115 | |
116 | for (i = 0; i < count; ++i) { | |
62e76326 | 117 | assert(!CBIT_TEST(*mask, enums[i])); /* check for duplicates */ |
118 | CBIT_SET(*mask, enums[i]); | |
7faf2bdb | 119 | } |
7faf2bdb | 120 | } |
121 | ||
2246b732 | 122 | /* same as httpHeaderPutStr, but formats the string using snprintf first */ |
2246b732 | 123 | void |
eeb423fb | 124 | httpHeaderPutStrf(HttpHeader * hdr, http_hdr_type id, const char *fmt,...) |
2246b732 | 125 | { |
9bc73deb | 126 | va_list args; |
127 | va_start(args, fmt); | |
62e76326 | 128 | |
2246b732 | 129 | httpHeaderPutStrvf(hdr, id, fmt, args); |
130 | va_end(args); | |
131 | } | |
132 | ||
133 | /* used by httpHeaderPutStrf */ | |
134 | static void | |
135 | httpHeaderPutStrvf(HttpHeader * hdr, http_hdr_type id, const char *fmt, va_list vargs) | |
136 | { | |
2246b732 | 137 | MemBuf mb; |
2fe7eff9 | 138 | mb.init(); |
139 | mb.vPrintf(fmt, vargs); | |
a9925b40 | 140 | hdr->putStr(id, mb.buf); |
2fe7eff9 | 141 | mb.clean(); |
2246b732 | 142 | } |
143 | ||
9035d1d5 | 144 | /** wrapper arrounf PutContRange */ |
d192d11f | 145 | void |
47f6e231 | 146 | httpHeaderAddContRange(HttpHeader * hdr, HttpHdrRangeSpec spec, int64_t ent_len) |
d192d11f | 147 | { |
148 | HttpHdrContRange *cr = httpHdrContRangeCreate(); | |
149 | assert(hdr && ent_len >= 0); | |
150 | httpHdrContRangeSet(cr, spec, ent_len); | |
a9925b40 | 151 | hdr->putContRange(cr); |
d192d11f | 152 | httpHdrContRangeDestroy(cr); |
153 | } | |
154 | ||
9035d1d5 | 155 | /** |
9bc73deb | 156 | * return true if a given directive is found in at least one of |
157 | * the "connection" header-fields note: if HDR_PROXY_CONNECTION is | |
158 | * present we ignore HDR_CONNECTION. | |
99edd1c3 | 159 | */ |
160 | int | |
5999b776 | 161 | httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive) |
99edd1c3 | 162 | { |
30abd221 | 163 | String list; |
9bc73deb | 164 | int res; |
165 | /* what type of header do we have? */ | |
62e76326 | 166 | |
95e78500 | 167 | #if USE_HTTP_VIOLATIONS |
a9925b40 | 168 | if (hdr->has(HDR_PROXY_CONNECTION)) |
95e78500 AJ |
169 | list = hdr->getList(HDR_PROXY_CONNECTION); |
170 | else | |
171 | #endif | |
2e881a6f A |
172 | if (hdr->has(HDR_CONNECTION)) |
173 | list = hdr->getList(HDR_CONNECTION); | |
174 | else | |
175 | return 0; | |
9bc73deb | 176 | |
9bc73deb | 177 | res = strListIsMember(&list, directive, ','); |
62e76326 | 178 | |
30abd221 | 179 | list.clean(); |
180 | ||
9bc73deb | 181 | return res; |
99edd1c3 | 182 | } |
183 | ||
b50e327b | 184 | /** handy to printf prefixes of potentially very long buffers */ |
7faf2bdb | 185 | const char * |
d8b249ef | 186 | getStringPrefix(const char *str, const char *end) |
7faf2bdb | 187 | { |
d8b249ef | 188 | #define SHORT_PREFIX_SIZE 512 |
7faf2bdb | 189 | LOCAL_ARRAY(char, buf, SHORT_PREFIX_SIZE); |
b644367b | 190 | const int sz = 1 + (end ? end - str : strlen(str)); |
d8b249ef | 191 | xstrncpy(buf, str, (sz > SHORT_PREFIX_SIZE) ? SHORT_PREFIX_SIZE : sz); |
7faf2bdb | 192 | return buf; |
193 | } | |
b5107edb | 194 | |
b50e327b | 195 | /** |
b5107edb | 196 | * parses an int field, complains if soemthing went wrong, returns true on |
197 | * success | |
198 | */ | |
199 | int | |
200 | httpHeaderParseInt(const char *start, int *value) | |
201 | { | |
202 | assert(value); | |
203 | *value = atoi(start); | |
62e76326 | 204 | |
b6a2f15e | 205 | if (!*value && !xisdigit(*start)) { |
bf8fe701 | 206 | debugs(66, 2, "failed to parse an int header field near '" << start << "'"); |
62e76326 | 207 | return 0; |
b5107edb | 208 | } |
62e76326 | 209 | |
b5107edb | 210 | return 1; |
211 | } | |
212 | ||
47f6e231 | 213 | int |
214 | httpHeaderParseOffset(const char *start, int64_t * value) | |
215 | { | |
66e255bc | 216 | errno = 0; |
47f6e231 | 217 | int64_t res = strtoll(start, NULL, 10); |
218 | if (!res && EINVAL == errno) /* maybe not portable? */ | |
26ac0430 | 219 | return 0; |
47f6e231 | 220 | *value = res; |
221 | return 1; | |
222 | } | |
223 | ||
b50e327b AJ |
224 | /** |
225 | * Parses a quoted-string field (RFC 2616 section 2.2), complains if | |
43ae1d95 | 226 | * something went wrong, returns non-zero on success. |
34460e19 | 227 | * Un-escapes quoted-pair characters found within the string. |
229af339 | 228 | * start should point at the first double-quote. |
43ae1d95 | 229 | */ |
230 | int | |
34460e19 | 231 | httpHeaderParseQuotedString(const char *start, const int len, String *val) |
43ae1d95 | 232 | { |
233 | const char *end, *pos; | |
30abd221 | 234 | val->clean(); |
9abd1514 | 235 | if (*start != '"') { |
5f5ddef6 | 236 | debugs(66, 2, HERE << "failed to parse a quoted-string header field near '" << start << "'"); |
6d97f5f1 | 237 | return 0; |
9abd1514 | 238 | } |
43ae1d95 | 239 | pos = start + 1; |
240 | ||
34460e19 | 241 | while (*pos != '"' && len > (pos-start)) { |
5f5ddef6 CT |
242 | |
243 | if (*pos =='\r') { | |
95dc7ff4 | 244 | ++pos; |
5f5ddef6 CT |
245 | if ((pos-start) > len || *pos != '\n') { |
246 | debugs(66, 2, HERE << "failed to parse a quoted-string header field with '\\r' octet " << (start-pos) | |
247 | << " bytes into '" << start << "'"); | |
248 | val->clean(); | |
249 | return 0; | |
250 | } | |
251 | } | |
252 | ||
253 | if (*pos == '\n') { | |
95dc7ff4 | 254 | ++pos; |
5f5ddef6 CT |
255 | if ( (pos-start) > len || (*pos != ' ' && *pos != '\t')) { |
256 | debugs(66, 2, HERE << "failed to parse multiline quoted-string header field '" << start << "'"); | |
257 | val->clean(); | |
258 | return 0; | |
259 | } | |
260 | // TODO: replace the entire LWS with a space | |
261 | val->append(" "); | |
95dc7ff4 | 262 | ++pos; |
5f5ddef6 CT |
263 | debugs(66, 2, HERE << "len < pos-start => " << len << " < " << (pos-start)); |
264 | continue; | |
265 | } | |
266 | ||
a0133f10 | 267 | bool quoted = (*pos == '\\'); |
5f5ddef6 | 268 | if (quoted) { |
95dc7ff4 | 269 | ++pos; |
5f5ddef6 CT |
270 | if (!*pos || (pos-start) > len) { |
271 | debugs(66, 2, HERE << "failed to parse a quoted-string header field near '" << start << "'"); | |
272 | val->clean(); | |
273 | return 0; | |
274 | } | |
6d97f5f1 | 275 | } |
34460e19 | 276 | end = pos; |
c4b86597 | 277 | while (end < (start+len) && *end != '\\' && *end != '\"' && (unsigned char)*end > 0x1F && *end != 0x7F) |
95dc7ff4 | 278 | ++end; |
c4b86597 | 279 | if (((unsigned char)*end <= 0x1F && *end != '\r' && *end != '\n') || *end == 0x7F) { |
5f5ddef6 | 280 | debugs(66, 2, HERE << "failed to parse a quoted-string header field with CTL octet " << (start-pos) |
34460e19 AJ |
281 | << " bytes into '" << start << "'"); |
282 | val->clean(); | |
283 | return 0; | |
284 | } | |
6d97f5f1 A |
285 | val->append(pos, end-pos); |
286 | pos = end; | |
43ae1d95 | 287 | } |
5f5ddef6 CT |
288 | |
289 | if (*pos != '\"') { | |
290 | debugs(66, 2, HERE << "failed to parse a quoted-string header field which did not end with \" "); | |
291 | val->clean(); | |
292 | return 0; | |
293 | } | |
9abd1514 HN |
294 | /* Make sure it's defined even if empty "" */ |
295 | if (!val->defined()) | |
6d97f5f1 | 296 | val->limitInit("", 0); |
9abd1514 | 297 | return 1; |
43ae1d95 | 298 | } |
299 | ||
b50e327b AJ |
300 | /** |
301 | * Checks the anonymizer (header_access) configuration. | |
4f4611bf | 302 | * |
b50e327b AJ |
303 | * \retval 0 Header is explicitly blocked for removal |
304 | * \retval 1 Header is explicitly allowed | |
305 | * \retval 1 Header has been replaced, the current version can be used. | |
306 | * \retval 1 Header has no access controls to test | |
6bccf575 | 307 | */ |
2d72d4fd | 308 | static int |
8c01ada0 | 309 | httpHdrMangle(HttpHeaderEntry * e, HttpRequest * request, int req_or_rep) |
6bccf575 | 310 | { |
e9b1e111 | 311 | int retval; |
312 | ||
6bccf575 | 313 | /* check with anonymizer tables */ |
3b07476b | 314 | HeaderManglers *hms = NULL; |
6bccf575 | 315 | assert(e); |
8c01ada0 | 316 | |
317 | if (ROR_REQUEST == req_or_rep) { | |
3b07476b | 318 | hms = Config.request_header_access; |
8c01ada0 | 319 | } else if (ROR_REPLY == req_or_rep) { |
3b07476b | 320 | hms = Config.reply_header_access; |
8c01ada0 | 321 | } else { |
322 | /* error. But let's call it "request". */ | |
3b07476b | 323 | hms = Config.request_header_access; |
8c01ada0 | 324 | } |
325 | ||
3b07476b CT |
326 | /* manglers are not configured for this message kind */ |
327 | if (!hms) | |
328 | return 1; | |
329 | ||
330 | const header_mangler *hm = hms->find(*e); | |
331 | ||
b50e327b | 332 | /* mangler or checklist went away. default allow */ |
af6a12ee | 333 | if (!hm || !hm->access_list) { |
b50e327b AJ |
334 | return 1; |
335 | } | |
336 | ||
c0941a6a | 337 | ACLFilledChecklist checklist(hm->access_list, request, NULL); |
62e76326 | 338 | |
2efeb0b7 | 339 | if (checklist.fastCheck() == ACCESS_ALLOWED) { |
b50e327b | 340 | /* aclCheckFast returns true for allow. */ |
62e76326 | 341 | retval = 1; |
a453662f | 342 | } else if (NULL == hm->replacement) { |
62e76326 | 343 | /* It was denied, and we don't have any replacement */ |
344 | retval = 0; | |
a453662f | 345 | } else { |
62e76326 | 346 | /* It was denied, but we have a replacement. Replace the |
347 | * header on the fly, and return that the new header | |
348 | * is allowed. | |
349 | */ | |
350 | e->value = hm->replacement; | |
351 | retval = 1; | |
a453662f | 352 | } |
e9b1e111 | 353 | |
e9b1e111 | 354 | return retval; |
6bccf575 | 355 | } |
356 | ||
b50e327b | 357 | /** Mangles headers for a list of headers. */ |
6bccf575 | 358 | void |
8c01ada0 | 359 | httpHdrMangleList(HttpHeader * l, HttpRequest * request, int req_or_rep) |
6bccf575 | 360 | { |
361 | HttpHeaderEntry *e; | |
362 | HttpHeaderPos p = HttpHeaderInitPos; | |
62e76326 | 363 | |
ba9fb01d | 364 | int headers_deleted = 0; |
a9925b40 | 365 | while ((e = l->getEntry(&p))) |
8c01ada0 | 366 | if (0 == httpHdrMangle(e, request, req_or_rep)) |
ba9fb01d | 367 | l->delAt(p, headers_deleted); |
368 | ||
369 | if (headers_deleted) | |
370 | l->refreshMask(); | |
6bccf575 | 371 | } |
5967c0bf | 372 | |
3b07476b CT |
373 | static |
374 | void header_mangler_clean(header_mangler &m) | |
375 | { | |
376 | aclDestroyAccessList(&m.access_list); | |
377 | safe_free(m.replacement); | |
378 | } | |
379 | ||
380 | static | |
381 | void header_mangler_dump_access(StoreEntry * entry, const char *option, | |
d3abcb0d | 382 | const header_mangler &m, const char *name) |
3b07476b CT |
383 | { |
384 | if (m.access_list != NULL) { | |
385 | storeAppendPrintf(entry, "%s ", option); | |
386 | dump_acl_access(entry, name, m.access_list); | |
387 | } | |
388 | } | |
389 | ||
390 | static | |
391 | void header_mangler_dump_replacement(StoreEntry * entry, const char *option, | |
d3abcb0d | 392 | const header_mangler &m, const char *name) |
3b07476b CT |
393 | { |
394 | if (m.replacement) | |
395 | storeAppendPrintf(entry, "%s %s %s\n", option, name, m.replacement); | |
396 | } | |
397 | ||
398 | HeaderManglers::HeaderManglers() | |
399 | { | |
400 | memset(known, 0, sizeof(known)); | |
401 | memset(&all, 0, sizeof(all)); | |
402 | } | |
403 | ||
404 | HeaderManglers::~HeaderManglers() | |
405 | { | |
95dc7ff4 | 406 | for (int i = 0; i < HDR_ENUM_END; ++i) |
3b07476b CT |
407 | header_mangler_clean(known[i]); |
408 | ||
409 | typedef ManglersByName::iterator MBNI; | |
410 | for (MBNI i = custom.begin(); i != custom.end(); ++i) | |
411 | header_mangler_clean(i->second); | |
412 | ||
413 | header_mangler_clean(all); | |
414 | } | |
415 | ||
416 | void | |
417 | HeaderManglers::dumpAccess(StoreEntry * entry, const char *name) const | |
5967c0bf | 418 | { |
95dc7ff4 | 419 | for (int i = 0; i < HDR_ENUM_END; ++i) { |
3b07476b CT |
420 | header_mangler_dump_access(entry, name, known[i], |
421 | httpHeaderNameById(i)); | |
5967c0bf | 422 | } |
423 | ||
3b07476b CT |
424 | typedef ManglersByName::const_iterator MBNCI; |
425 | for (MBNCI i = custom.begin(); i != custom.end(); ++i) | |
426 | header_mangler_dump_access(entry, name, i->second, i->first.c_str()); | |
427 | ||
428 | header_mangler_dump_access(entry, name, all, "All"); | |
5967c0bf | 429 | } |
3b07476b CT |
430 | |
431 | void | |
432 | HeaderManglers::dumpReplacement(StoreEntry * entry, const char *name) const | |
433 | { | |
95dc7ff4 | 434 | for (int i = 0; i < HDR_ENUM_END; ++i) { |
3b07476b CT |
435 | header_mangler_dump_replacement(entry, name, known[i], |
436 | httpHeaderNameById(i)); | |
437 | } | |
438 | ||
439 | typedef ManglersByName::const_iterator MBNCI; | |
440 | for (MBNCI i = custom.begin(); i != custom.end(); ++i) { | |
441 | header_mangler_dump_replacement(entry, name, i->second, | |
442 | i->first.c_str()); | |
443 | } | |
444 | ||
445 | header_mangler_dump_replacement(entry, name, all, "All"); | |
446 | } | |
447 | ||
448 | header_mangler * | |
449 | HeaderManglers::track(const char *name) | |
450 | { | |
451 | int id = httpHeaderIdByNameDef(name, strlen(name)); | |
452 | ||
453 | if (id == HDR_BAD_HDR) { // special keyword or a custom header | |
454 | if (strcmp(name, "All") == 0) | |
455 | id = HDR_ENUM_END; | |
456 | else if (strcmp(name, "Other") == 0) | |
457 | id = HDR_OTHER; | |
458 | } | |
459 | ||
460 | header_mangler *m = NULL; | |
461 | if (id == HDR_ENUM_END) { | |
462 | m = &all; | |
d3abcb0d | 463 | } else if (id == HDR_BAD_HDR) { |
3b07476b CT |
464 | m = &custom[name]; |
465 | } else { | |
466 | m = &known[id]; // including HDR_OTHER | |
467 | } | |
468 | ||
469 | assert(m); | |
470 | return m; | |
471 | } | |
472 | ||
473 | void | |
474 | HeaderManglers::setReplacement(const char *name, const char *value) | |
475 | { | |
476 | // for backword compatibility, we allow replacements to be configured | |
477 | // for headers w/o access rules, but such replacements are ignored | |
478 | header_mangler *m = track(name); | |
479 | ||
480 | safe_free(m->replacement); // overwrite old value if any | |
481 | m->replacement = xstrdup(value); | |
482 | } | |
483 | ||
484 | const header_mangler * | |
485 | HeaderManglers::find(const HttpHeaderEntry &e) const | |
486 | { | |
487 | // a known header with a configured ACL list | |
488 | if (e.id != HDR_OTHER && 0 <= e.id && e.id < HDR_ENUM_END && | |
d3abcb0d | 489 | known[e.id].access_list) |
3b07476b CT |
490 | return &known[e.id]; |
491 | ||
492 | // a custom header | |
493 | if (e.id == HDR_OTHER) { | |
494 | // does it have an ACL list configured? | |
495 | // Optimize: use a name type that we do not need to convert to here | |
496 | const ManglersByName::const_iterator i = custom.find(e.name.termedBuf()); | |
497 | if (i != custom.end()) | |
498 | return &i->second; | |
499 | } | |
500 | ||
501 | // Next-to-last resort: "Other" rules match any custom header | |
502 | if (e.id == HDR_OTHER && known[HDR_OTHER].access_list) | |
503 | return &known[HDR_OTHER]; | |
504 | ||
505 | // Last resort: "All" rules match any header | |
506 | if (all.access_list) | |
507 | return &all; | |
508 | ||
509 | return NULL; | |
510 | } | |
511 | ||
f4698e0b | 512 | void |
4bf68cfa | 513 | httpHdrAdd(HttpHeader *heads, HttpRequest *request, const AccessLogEntryPointer &al, HeaderWithAclList &headersAdd) |
f4698e0b CT |
514 | { |
515 | ACLFilledChecklist checklist(NULL, request, NULL); | |
516 | ||
517 | for (HeaderWithAclList::const_iterator hwa = headersAdd.begin(); hwa != headersAdd.end(); ++hwa) { | |
518 | if (!hwa->aclList || checklist.fastCheck(hwa->aclList) == ACCESS_ALLOWED) { | |
519 | const char *fieldValue = NULL; | |
520 | MemBuf mb; | |
521 | if (hwa->quoted) { | |
4bf68cfa | 522 | if (al != NULL) { |
f4698e0b | 523 | mb.init(); |
4bf68cfa | 524 | hwa->valueFormat->assemble(mb, al, 0); |
f4698e0b CT |
525 | fieldValue = mb.content(); |
526 | } | |
527 | } else { | |
528 | fieldValue = hwa->fieldValue.c_str(); | |
529 | } | |
530 | ||
531 | if (!fieldValue || fieldValue[0] == '\0') | |
532 | fieldValue = "-"; | |
533 | ||
999aa5d2 A |
534 | HttpHeaderEntry *e = new HttpHeaderEntry(hwa->fieldId, hwa->fieldName.c_str(), |
535 | fieldValue); | |
f4698e0b CT |
536 | heads->addEntry(e); |
537 | } | |
538 | } | |
539 | } |