2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 55 HTTP Header */
12 #include "base/CharacterSet.h"
13 #include "base/EnumIterator.h"
16 #include "http/ContentLengthInterpreter.h"
17 #include "HttpHdrCc.h"
18 #include "HttpHdrContRange.h"
19 #include "HttpHdrScTarget.h" // also includes HttpHdrSc.h
20 #include "HttpHeader.h"
21 #include "HttpHeaderFieldInfo.h"
22 #include "HttpHeaderStat.h"
23 #include "HttpHeaderTools.h"
25 #include "mgr/Registration.h"
26 #include "mime_header.h"
27 #include "profiler/Profiler.h"
29 #include "sbuf/StringConvert.h"
30 #include "SquidConfig.h"
34 #include "TimeOrTag.h"
39 /* XXX: the whole set of API managing the entries vector should be rethought
40 * after the parse4r-ng effort is complete.
44 * On naming conventions:
46 * HTTP/1.1 defines message-header as
48 * message-header = field-name ":" [ field-value ] CRLF
50 * field-value = *( field-content | LWS )
52 * HTTP/1.1 does not give a name name a group of all message-headers in a message.
53 * Squid 1.1 seems to refer to that group _plus_ start-line as "headers".
55 * HttpHeader is an object that represents all message-headers in a message.
56 * HttpHeader does not manage start-line.
58 * HttpHeader is implemented as a collection of header "entries".
59 * An entry is a (field_id, field_name, field_value) triplet.
63 * local constants and vars
66 // statistics counters for headers. clients must not allow Http::HdrType::BAD_HDR to be counted
67 std::vector
<HttpHeaderFieldStat
> headerStatsTable(Http::HdrType::enumEnd_
);
69 /* request-only headers. Used for cachemgr */
70 static HttpHeaderMask RequestHeadersMask
; /* set run-time using RequestHeaders */
72 /* reply-only headers. Used for cachemgr */
73 static HttpHeaderMask ReplyHeadersMask
; /* set run-time using ReplyHeaders */
75 /* header accounting */
76 // NP: keep in sync with enum http_hdr_owner_type
77 static HttpHeaderStat HttpHeaderStats
[] = {
78 HttpHeaderStat(/*hoNone*/ "all", NULL
),
80 HttpHeaderStat(/*hoHtcpReply*/ "HTCP reply", &ReplyHeadersMask
),
82 HttpHeaderStat(/*hoRequest*/ "request", &RequestHeadersMask
),
83 HttpHeaderStat(/*hoReply*/ "reply", &ReplyHeadersMask
)
89 static int HttpHeaderStatCount
= countof(HttpHeaderStats
);
91 static int HeaderEntryParsedCount
= 0;
94 * forward declarations and local routines
99 // update parse statistics for header id; if error is true also account
100 // for errors and write to debug log what happened
101 static void httpHeaderNoteParsedEntry(Http::HdrType id
, String
const &value
, bool error
);
102 static void httpHeaderStatDump(const HttpHeaderStat
* hs
, StoreEntry
* e
);
103 /** store report about current header usage and other stats */
104 static void httpHeaderStoreReport(StoreEntry
* e
);
107 * Module initialization routines
111 httpHeaderRegisterWithCacheManager(void)
113 Mgr::RegisterAction("http_headers",
114 "HTTP Header Statistics",
115 httpHeaderStoreReport
, 0, 1);
119 httpHeaderInitModule(void)
121 /* check that we have enough space for masks */
122 assert(8 * sizeof(HttpHeaderMask
) >= Http::HdrType::enumEnd_
);
124 // masks are needed for stats page still
125 for (auto h
: WholeEnum
<Http::HdrType
>()) {
126 if (Http::HeaderLookupTable
.lookup(h
).request
)
127 CBIT_SET(RequestHeadersMask
,h
);
128 if (Http::HeaderLookupTable
.lookup(h
).reply
)
129 CBIT_SET(ReplyHeadersMask
,h
);
132 /* header stats initialized by class constructor */
133 assert(HttpHeaderStatCount
== hoReply
+ 1);
135 /* init dependent modules */
136 httpHdrCcInitModule();
137 httpHdrScInitModule();
139 httpHeaderRegisterWithCacheManager();
143 * HttpHeader Implementation
146 HttpHeader::HttpHeader() : owner (hoNone
), len (0), conflictingContentLength_(false)
148 httpHeaderMaskInit(&mask
, 0);
151 HttpHeader::HttpHeader(const http_hdr_owner_type anOwner
): owner(anOwner
), len(0), conflictingContentLength_(false)
153 assert(anOwner
> hoNone
&& anOwner
< hoEnd
);
154 debugs(55, 7, "init-ing hdr: " << this << " owner: " << owner
);
155 httpHeaderMaskInit(&mask
, 0);
158 HttpHeader::HttpHeader(const HttpHeader
&other
): owner(other
.owner
), len(other
.len
), conflictingContentLength_(false)
160 httpHeaderMaskInit(&mask
, 0);
161 update(&other
); // will update the mask as well
164 HttpHeader::~HttpHeader()
170 HttpHeader::operator =(const HttpHeader
&other
)
172 if (this != &other
) {
173 // we do not really care, but the caller probably does
174 assert(owner
== other
.owner
);
176 update(&other
); // will update the mask as well
178 conflictingContentLength_
= other
.conflictingContentLength_
;
187 assert(owner
> hoNone
&& owner
< hoEnd
);
188 debugs(55, 7, "cleaning hdr: " << this << " owner: " << owner
);
190 PROF_start(HttpHeaderClean
);
192 if (owner
<= hoReply
) {
194 * An unfortunate bug. The entries array is initialized
195 * such that count is set to zero. httpHeaderClean() seems to
196 * be called both when 'hdr' is created, and destroyed. Thus,
197 * we accumulate a large number of zero counts for 'hdr' before
198 * it is ever used. Can't think of a good way to fix it, except
199 * adding a state variable that indicates whether or not 'hdr'
200 * has been used. As a hack, just never count zero-sized header
203 if (!entries
.empty())
204 HttpHeaderStats
[owner
].hdrUCountDistr
.count(entries
.size());
206 ++ HttpHeaderStats
[owner
].destroyedCount
;
208 HttpHeaderStats
[owner
].busyDestroyedCount
+= entries
.size() > 0;
209 } // if (owner <= hoReply)
211 for (HttpHeaderEntry
*e
: entries
) {
214 if (!Http::any_valid_header(e
->id
)) {
215 debugs(55, DBG_CRITICAL
, "BUG: invalid entry (" << e
->id
<< "). Ignored.");
217 if (owner
<= hoReply
)
218 HttpHeaderStats
[owner
].fieldTypeDistr
.count(e
->id
);
224 httpHeaderMaskInit(&mask
, 0);
226 conflictingContentLength_
= false;
227 PROF_stop(HttpHeaderClean
);
230 /* append entries (also see httpHeaderUpdate) */
232 HttpHeader::append(const HttpHeader
* src
)
236 debugs(55, 7, "appending hdr: " << this << " += " << src
);
238 for (auto e
: src
->entries
) {
240 addEntry(e
->clone());
244 /// check whether the fresh header has any new/changed updatable fields
246 HttpHeader::needUpdate(HttpHeader
const *fresh
) const
248 for (const auto e
: fresh
->entries
) {
249 if (!e
|| skipUpdateHeader(e
->id
))
252 if (!hasNamed(e
->name
, &value
) ||
253 (value
!= fresh
->getByName(e
->name
)))
260 HttpHeader::updateWarnings()
263 HttpHeaderPos pos
= HttpHeaderInitPos
;
265 // RFC 7234, section 4.3.4: delete 1xx warnings and retain 2xx warnings
266 while (HttpHeaderEntry
*e
= getEntry(&pos
)) {
267 if (e
->id
== Http::HdrType::WARNING
&& (e
->getInt()/100 == 1) )
273 HttpHeader::skipUpdateHeader(const Http::HdrType id
) const
275 // RFC 7234, section 4.3.4: use fields other from Warning for update
276 return id
== Http::HdrType::WARNING
;
280 HttpHeader::update(HttpHeader
const *fresh
)
283 assert(this != fresh
);
285 // Optimization: Finding whether a header field changed is expensive
286 // and probably not worth it except for collapsed revalidation needs.
287 if (Config
.onoff
.collapsed_forwarding
&& !needUpdate(fresh
))
292 const HttpHeaderEntry
*e
;
293 HttpHeaderPos pos
= HttpHeaderInitPos
;
295 while ((e
= fresh
->getEntry(&pos
))) {
296 /* deny bad guys (ok to check for Http::HdrType::OTHER) here */
298 if (skipUpdateHeader(e
->id
))
301 if (e
->id
!= Http::HdrType::OTHER
)
307 pos
= HttpHeaderInitPos
;
308 while ((e
= fresh
->getEntry(&pos
))) {
309 /* deny bad guys (ok to check for Http::HdrType::OTHER) here */
311 if (skipUpdateHeader(e
->id
))
314 debugs(55, 7, "Updating header '" << Http::HeaderLookupTable
.lookup(e
->id
).name
<< "' in cached entry");
316 addEntry(e
->clone());
322 HttpHeader::Isolate(const char **parse_start
, size_t l
, const char **blk_start
, const char **blk_end
)
325 * parse_start points to the first line of HTTP message *headers*,
326 * not including the request or status lines
328 const size_t end
= headersEnd(*parse_start
, l
);
331 *blk_start
= *parse_start
;
332 *blk_end
= *parse_start
+ end
- 1;
333 assert(**blk_end
== '\n');
334 // Point blk_end to the first character after the last header field.
335 // In other words, blk_end should point to the CR?LF header terminator.
336 if (end
> 1 && *(*blk_end
- 1) == '\r')
344 HttpHeader::parse(const char *buf
, size_t buf_len
, bool atEnd
, size_t &hdr_sz
)
346 const char *parse_start
= buf
;
347 const char *blk_start
, *blk_end
;
350 if (!Isolate(&parse_start
, buf_len
, &blk_start
, &blk_end
)) {
351 // XXX: do not parse non-isolated headers even if the connection is closed.
352 // Treat unterminated headers as "partial headers" framing errors.
355 blk_start
= parse_start
;
356 blk_end
= blk_start
+ strlen(blk_start
);
359 if (parse(blk_start
, blk_end
- blk_start
)) {
360 hdr_sz
= parse_start
- buf
;
367 HttpHeader::parse(const char *header_start
, size_t hdrLen
)
369 const char *field_ptr
= header_start
;
370 const char *header_end
= header_start
+ hdrLen
; // XXX: remove
371 int warnOnError
= (Config
.onoff
.relaxed_header_parser
<= 0 ? DBG_IMPORTANT
: 2);
373 PROF_start(HttpHeaderParse
);
375 assert(header_start
&& header_end
);
376 debugs(55, 7, "parsing hdr: (" << this << ")" << std::endl
<< getStringPrefix(header_start
, hdrLen
));
377 ++ HttpHeaderStats
[owner
].parsedCount
;
380 if ((nulpos
= (char*)memchr(header_start
, '\0', hdrLen
))) {
381 debugs(55, DBG_IMPORTANT
, "WARNING: HTTP header contains NULL characters {" <<
382 getStringPrefix(header_start
, nulpos
-header_start
) << "}\nNULL\n{" << getStringPrefix(nulpos
+1, hdrLen
-(nulpos
-header_start
)-1));
383 PROF_stop(HttpHeaderParse
);
388 Http::ContentLengthInterpreter
clen(warnOnError
);
389 /* common format headers are "<name>:[ws]<value>" lines delimited by <CRLF>.
390 * continuation lines start with a (single) space or tab */
391 while (field_ptr
< header_end
) {
392 const char *field_start
= field_ptr
;
393 const char *field_end
;
396 const char *this_line
= field_ptr
;
397 field_ptr
= (const char *)memchr(field_ptr
, '\n', header_end
- field_ptr
);
401 PROF_stop(HttpHeaderParse
);
406 field_end
= field_ptr
;
408 ++field_ptr
; /* Move to next line */
410 if (field_end
> this_line
&& field_end
[-1] == '\r') {
411 --field_end
; /* Ignore CR LF */
413 if (owner
== hoRequest
&& field_end
> this_line
) {
415 for (const char *p
= this_line
; p
< field_end
&& cr_only
; ++p
) {
420 debugs(55, DBG_IMPORTANT
, "SECURITY WARNING: Rejecting HTTP request with a CR+ "
421 "header field to prevent request smuggling attacks: {" <<
422 getStringPrefix(header_start
, hdrLen
) << "}");
423 PROF_stop(HttpHeaderParse
);
430 /* Barf on stray CR characters */
431 if (memchr(this_line
, '\r', field_end
- this_line
)) {
432 debugs(55, warnOnError
, "WARNING: suspicious CR characters in HTTP header {" <<
433 getStringPrefix(field_start
, field_end
-field_start
) << "}");
435 if (Config
.onoff
.relaxed_header_parser
) {
436 char *p
= (char *) this_line
; /* XXX Warning! This destroys original header content and violates specifications somewhat */
438 while ((p
= (char *)memchr(p
, '\r', field_end
- p
)) != NULL
) {
443 PROF_stop(HttpHeaderParse
);
449 if (this_line
+ 1 == field_end
&& this_line
> field_start
) {
450 debugs(55, warnOnError
, "WARNING: Blank continuation line in HTTP header {" <<
451 getStringPrefix(header_start
, hdrLen
) << "}");
452 PROF_stop(HttpHeaderParse
);
456 } while (field_ptr
< header_end
&& (*field_ptr
== ' ' || *field_ptr
== '\t'));
458 if (field_start
== field_end
) {
459 if (field_ptr
< header_end
) {
460 debugs(55, warnOnError
, "WARNING: unparseable HTTP header field near {" <<
461 getStringPrefix(field_start
, hdrLen
-(field_start
-header_start
)) << "}");
462 PROF_stop(HttpHeaderParse
);
467 break; /* terminating blank line */
471 if ((e
= HttpHeaderEntry::parse(field_start
, field_end
)) == NULL
) {
472 debugs(55, warnOnError
, "WARNING: unparseable HTTP header field {" <<
473 getStringPrefix(field_start
, field_end
-field_start
) << "}");
474 debugs(55, warnOnError
, " in {" << getStringPrefix(header_start
, hdrLen
) << "}");
476 if (Config
.onoff
.relaxed_header_parser
)
479 PROF_stop(HttpHeaderParse
);
484 if (e
->id
== Http::HdrType::CONTENT_LENGTH
&& !clen
.checkField(e
->value
)) {
487 if (Config
.onoff
.relaxed_header_parser
)
488 continue; // clen has printed any necessary warnings
490 PROF_stop(HttpHeaderParse
);
495 /* AYJ 2017-05-23: I suspect we need to change this whitespace check to conform to the
496 updated WSP character set in RFC 7230/7231. For now I left it as the
497 characters in w_space which the previous code was using. */
498 static CharacterSet wsp
= (CharacterSet::WSP
+ CharacterSet::CR
+ CharacterSet::LF
);
499 if (e
->id
== Http::HdrType::OTHER
&& e
->name
.findFirstOf(wsp
) != SBuf::npos
) {
500 debugs(55, warnOnError
, "WARNING: found whitespace in HTTP header name {" <<
501 getStringPrefix(field_start
, field_end
-field_start
) << "}");
503 if (!Config
.onoff
.relaxed_header_parser
) {
505 PROF_stop(HttpHeaderParse
);
514 if (clen
.headerWideProblem
) {
515 debugs(55, warnOnError
, "WARNING: " << clen
.headerWideProblem
<<
516 " Content-Length field values in" <<
517 Raw("header", header_start
, hdrLen
));
521 // RFC 2616 section 4.4: ignore Content-Length with Transfer-Encoding
522 // RFC 7230 section 3.3.3 #3: Transfer-Encoding overwrites Content-Length
523 delById(Http::HdrType::CONTENT_LENGTH
);
524 // and clen state becomes irrelevant
525 } else if (clen
.sawBad
) {
526 // ensure our callers do not accidentally see bad Content-Length values
527 delById(Http::HdrType::CONTENT_LENGTH
);
528 conflictingContentLength_
= true; // TODO: Rename to badContentLength_.
529 } else if (clen
.needsSanitizing
) {
530 // RFC 7230 section 3.3.2: MUST either reject or ... [sanitize];
531 // ensure our callers see a clean Content-Length value or none at all
532 delById(Http::HdrType::CONTENT_LENGTH
);
534 putInt64(Http::HdrType::CONTENT_LENGTH
, clen
.value
);
535 debugs(55, 5, "sanitized Content-Length to be " << clen
.value
);
539 PROF_stop(HttpHeaderParse
);
540 return 1; /* even if no fields where found, it is a valid header */
543 /* packs all the entries using supplied packer */
545 HttpHeader::packInto(Packable
* p
, bool mask_sensitive_info
) const
547 HttpHeaderPos pos
= HttpHeaderInitPos
;
548 const HttpHeaderEntry
*e
;
550 debugs(55, 7, this << " into " << p
<<
551 (mask_sensitive_info
? " while masking" : ""));
552 /* pack all entries one by one */
553 while ((e
= getEntry(&pos
))) {
554 if (!mask_sensitive_info
) {
559 bool maskThisEntry
= false;
561 case Http::HdrType::AUTHORIZATION
:
562 case Http::HdrType::PROXY_AUTHORIZATION
:
563 maskThisEntry
= true;
566 case Http::HdrType::FTP_ARGUMENTS
:
567 if (const HttpHeaderEntry
*cmd
= findEntry(Http::HdrType::FTP_COMMAND
))
568 maskThisEntry
= (cmd
->value
== "PASS");
575 p
->append(e
->name
.rawContent(), e
->name
.length());
576 p
->append(": ** NOT DISPLAYED **\r\n", 23);
582 /* Pack in the "special" entries */
587 /* returns next valid entry */
589 HttpHeader::getEntry(HttpHeaderPos
* pos
) const
592 assert(*pos
>= HttpHeaderInitPos
&& *pos
< static_cast<ssize_t
>(entries
.size()));
594 for (++(*pos
); *pos
< static_cast<ssize_t
>(entries
.size()); ++(*pos
)) {
596 return static_cast<HttpHeaderEntry
*>(entries
[*pos
]);
603 * returns a pointer to a specified entry if any
604 * note that we return one entry so it does not make much sense to ask for
608 HttpHeader::findEntry(Http::HdrType id
) const
610 assert(any_registered_header(id
));
611 assert(!Http::HeaderLookupTable
.lookup(id
).list
);
613 /* check mask first */
615 if (!CBIT_TEST(mask
, id
))
618 /* looks like we must have it, do linear search */
619 for (auto e
: entries
) {
620 if (e
&& e
->id
== id
)
624 /* hm.. we thought it was there, but it was not found */
626 return nullptr; /* not reached */
630 * same as httpHeaderFindEntry
633 HttpHeader::findLastEntry(Http::HdrType id
) const
635 assert(any_registered_header(id
));
636 assert(!Http::HeaderLookupTable
.lookup(id
).list
);
638 /* check mask first */
639 if (!CBIT_TEST(mask
, id
))
642 for (auto e
= entries
.rbegin(); e
!= entries
.rend(); ++e
) {
643 if (*e
&& (*e
)->id
== id
)
647 /* hm.. we thought it was there, but it was not found */
649 return nullptr; /* not reached */
653 HttpHeader::delByName(const SBuf
&name
)
656 HttpHeaderPos pos
= HttpHeaderInitPos
;
657 httpHeaderMaskInit(&mask
, 0); /* temporal inconsistency */
658 debugs(55, 9, "deleting '" << name
<< "' fields in hdr " << this);
660 while (const HttpHeaderEntry
*e
= getEntry(&pos
)) {
661 if (!e
->name
.caseCmp(name
))
664 CBIT_SET(mask
, e
->id
);
670 /* deletes all entries with a given id, returns the #entries deleted */
672 HttpHeader::delById(Http::HdrType id
)
674 debugs(55, 8, this << " del-by-id " << id
);
675 assert(any_registered_header(id
));
677 if (!CBIT_TEST(mask
, id
))
682 HttpHeaderPos pos
= HttpHeaderInitPos
;
683 while (HttpHeaderEntry
*e
= getEntry(&pos
)) {
685 delAt(pos
, count
); // deletes e
694 * deletes an entry at pos and leaves a gap; leaving a gap makes it
695 * possible to iterate(search) and delete fields at the same time
696 * NOTE: Does not update the header mask. Caller must follow up with
697 * a call to refreshMask() if headers_deleted was incremented.
700 HttpHeader::delAt(HttpHeaderPos pos
, int &headers_deleted
)
703 assert(pos
>= HttpHeaderInitPos
&& pos
< static_cast<ssize_t
>(entries
.size()));
704 e
= static_cast<HttpHeaderEntry
*>(entries
[pos
]);
706 /* decrement header length, allow for ": " and crlf */
707 len
-= e
->name
.length() + 2 + e
->value
.size() + 2;
714 * Compacts the header storage
717 HttpHeader::compact()
719 // TODO: optimize removal, or possibly make it so that's not needed.
720 entries
.erase( std::remove(entries
.begin(), entries
.end(), nullptr),
725 * Refreshes the header mask. Required after delAt() calls.
728 HttpHeader::refreshMask()
730 httpHeaderMaskInit(&mask
, 0);
731 debugs(55, 7, "refreshing the mask in hdr " << this);
732 for (auto e
: entries
) {
734 CBIT_SET(mask
, e
->id
);
739 * does not call e->clone() so one should not reuse "*e"
742 HttpHeader::addEntry(HttpHeaderEntry
* e
)
745 assert(any_HdrType_enum_value(e
->id
));
746 assert(e
->name
.length());
748 debugs(55, 7, this << " adding entry: " << e
->id
<< " at " << entries
.size());
750 if (e
->id
!= Http::HdrType::BAD_HDR
) {
751 if (CBIT_TEST(mask
, e
->id
)) {
752 ++ headerStatsTable
[e
->id
].repCount
;
754 CBIT_SET(mask
, e
->id
);
758 entries
.push_back(e
);
760 /* increment header length, allow for ": " and crlf */
761 len
+= e
->name
.length() + 2 + e
->value
.size() + 2;
765 * does not call e->clone() so one should not reuse "*e"
768 HttpHeader::insertEntry(HttpHeaderEntry
* e
)
771 assert(any_valid_header(e
->id
));
773 debugs(55, 7, this << " adding entry: " << e
->id
<< " at " << entries
.size());
775 // Http::HdrType::BAD_HDR is filtered out by assert_any_valid_header
776 if (CBIT_TEST(mask
, e
->id
)) {
777 ++ headerStatsTable
[e
->id
].repCount
;
779 CBIT_SET(mask
, e
->id
);
782 entries
.insert(entries
.begin(),e
);
784 /* increment header length, allow for ": " and crlf */
785 len
+= e
->name
.length() + 2 + e
->value
.size() + 2;
789 HttpHeader::getList(Http::HdrType id
, String
*s
) const
791 debugs(55, 9, this << " joining for id " << id
);
792 /* only fields from ListHeaders array can be "listed" */
793 assert(Http::HeaderLookupTable
.lookup(id
).list
);
795 if (!CBIT_TEST(mask
, id
))
798 for (auto e
: entries
) {
799 if (e
&& e
->id
== id
)
800 strListAdd(s
, e
->value
.termedBuf(), ',');
804 * note: we might get an empty (size==0) string if there was an "empty"
805 * header. This results in an empty length String, which may have a NULL
808 /* temporary warning: remove it? (Is it useful for diagnostics ?) */
810 debugs(55, 3, "empty list header: " << Http::HeaderLookupTable
.lookup(id
).name
<< "(" << id
<< ")");
812 debugs(55, 6, this << ": joined for id " << id
<< ": " << s
);
817 /* return a list of entries with the same id separated by ',' and ws */
819 HttpHeader::getList(Http::HdrType id
) const
822 HttpHeaderPos pos
= HttpHeaderInitPos
;
823 debugs(55, 9, this << "joining for id " << id
);
824 /* only fields from ListHeaders array can be "listed" */
825 assert(Http::HeaderLookupTable
.lookup(id
).list
);
827 if (!CBIT_TEST(mask
, id
))
832 while ((e
= getEntry(&pos
))) {
834 strListAdd(&s
, e
->value
.termedBuf(), ',');
838 * note: we might get an empty (size==0) string if there was an "empty"
839 * header. This results in an empty length String, which may have a NULL
842 /* temporary warning: remove it? (Is it useful for diagnostics ?) */
844 debugs(55, 3, "empty list header: " << Http::HeaderLookupTable
.lookup(id
).name
<< "(" << id
<< ")");
846 debugs(55, 6, this << ": joined for id " << id
<< ": " << s
);
851 /* return a string or list of entries with the same id separated by ',' and ws */
853 HttpHeader::getStrOrList(Http::HdrType id
) const
857 if (Http::HeaderLookupTable
.lookup(id
).list
)
860 if ((e
= findEntry(id
)))
867 * Returns the value of the specified header and/or an undefined String.
870 HttpHeader::getByName(const char *name
) const
873 // ignore presence: return undefined string if an empty header is present
874 (void)hasNamed(name
, strlen(name
), &result
);
879 HttpHeader::getByName(const SBuf
&name
) const
882 // ignore presence: return undefined string if an empty header is present
883 (void)hasNamed(name
, &result
);
888 HttpHeader::getById(Http::HdrType id
) const
891 (void)getByIdIfPresent(id
, &result
);
896 HttpHeader::hasNamed(const SBuf
&s
, String
*result
) const
898 return hasNamed(s
.rawContent(), s
.length(), result
);
902 HttpHeader::getByIdIfPresent(Http::HdrType id
, String
*result
) const
904 if (id
== Http::HdrType::BAD_HDR
)
909 *result
= getStrOrList(id
);
914 HttpHeader::hasNamed(const char *name
, unsigned int namelen
, String
*result
) const
917 HttpHeaderPos pos
= HttpHeaderInitPos
;
922 /* First try the quick path */
923 id
= Http::HeaderLookupTable
.lookup(name
,namelen
).id
;
925 if (id
!= Http::HdrType::BAD_HDR
) {
926 if (getByIdIfPresent(id
, result
))
930 /* Sorry, an unknown header name. Do linear search */
932 while ((e
= getEntry(&pos
))) {
933 if (e
->id
== Http::HdrType::OTHER
&& e
->name
.length() == namelen
&& e
->name
.caseCmp(name
, namelen
) == 0) {
937 strListAdd(result
, e
->value
.termedBuf(), ',');
945 * Returns a the value of the specified list member, if any.
948 HttpHeader::getByNameListMember(const char *name
, const char *member
, const char separator
) const
951 const char *pos
= NULL
;
954 int mlen
= strlen(member
);
958 header
= getByName(name
);
962 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
963 if (strncmp(item
, member
, mlen
) == 0 && item
[mlen
] == '=') {
964 result
.append(item
+ mlen
+ 1, ilen
- mlen
- 1);
973 * returns a the value of the specified list member, if any.
976 HttpHeader::getListMember(Http::HdrType id
, const char *member
, const char separator
) const
979 const char *pos
= NULL
;
982 int mlen
= strlen(member
);
984 assert(any_registered_header(id
));
986 header
= getStrOrList(id
);
989 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
990 if (strncmp(item
, member
, mlen
) == 0 && item
[mlen
] == '=') {
991 result
.append(item
+ mlen
+ 1, ilen
- mlen
- 1);
1000 /* test if a field is present */
1002 HttpHeader::has(Http::HdrType id
) const
1004 assert(any_registered_header(id
));
1005 debugs(55, 9, this << " lookup for " << id
);
1006 return CBIT_TEST(mask
, id
);
1010 HttpHeader::addVia(const AnyP::ProtocolVersion
&ver
, const HttpHeader
*from
)
1012 // TODO: do not add Via header for messages where Squid itself
1013 // generated the message (i.e., Downloader or ESI) there should be no Via header added at all.
1015 if (Config
.onoff
.via
) {
1017 // RFC 7230 section 5.7.1.: protocol-name is omitted when
1018 // the received protocol is HTTP.
1019 if (ver
.protocol
> AnyP::PROTO_NONE
&& ver
.protocol
< AnyP::PROTO_UNKNOWN
&&
1020 ver
.protocol
!= AnyP::PROTO_HTTP
&& ver
.protocol
!= AnyP::PROTO_HTTPS
)
1021 buf
.appendf("%s/", AnyP::ProtocolType_str
[ver
.protocol
]);
1022 buf
.appendf("%d.%d %s", ver
.major
, ver
.minor
, ThisCache
);
1023 const HttpHeader
*hdr
= from
? from
: this;
1024 SBuf strVia
= StringToSBuf(hdr
->getList(Http::HdrType::VIA
));
1025 if (!strVia
.isEmpty())
1026 strVia
.append(", ", 2);
1028 // XXX: putStr() still suffers from String size limits
1029 Must(strVia
.length() < String::SizeMaxXXX());
1030 delById(Http::HdrType::VIA
);
1031 putStr(Http::HdrType::VIA
, strVia
.c_str());
1036 HttpHeader::putInt(Http::HdrType id
, int number
)
1038 assert(any_registered_header(id
));
1039 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftInt
); /* must be of an appropriate type */
1040 assert(number
>= 0);
1041 addEntry(new HttpHeaderEntry(id
, SBuf(), xitoa(number
)));
1045 HttpHeader::putInt64(Http::HdrType id
, int64_t number
)
1047 assert(any_registered_header(id
));
1048 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftInt64
); /* must be of an appropriate type */
1049 assert(number
>= 0);
1050 addEntry(new HttpHeaderEntry(id
, SBuf(), xint64toa(number
)));
1054 HttpHeader::putTime(Http::HdrType id
, time_t htime
)
1056 assert(any_registered_header(id
));
1057 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftDate_1123
); /* must be of an appropriate type */
1059 addEntry(new HttpHeaderEntry(id
, SBuf(), mkrfc1123(htime
)));
1063 HttpHeader::putStr(Http::HdrType id
, const char *str
)
1065 assert(any_registered_header(id
));
1066 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftStr
); /* must be of an appropriate type */
1068 addEntry(new HttpHeaderEntry(id
, SBuf(), str
));
1072 HttpHeader::putAuth(const char *auth_scheme
, const char *realm
)
1074 assert(auth_scheme
&& realm
);
1075 httpHeaderPutStrf(this, Http::HdrType::WWW_AUTHENTICATE
, "%s realm=\"%s\"", auth_scheme
, realm
);
1079 HttpHeader::putCc(const HttpHdrCc
* cc
)
1082 /* remove old directives if any */
1083 delById(Http::HdrType::CACHE_CONTROL
);
1089 addEntry(new HttpHeaderEntry(Http::HdrType::CACHE_CONTROL
, SBuf(), mb
.buf
));
1095 HttpHeader::putContRange(const HttpHdrContRange
* cr
)
1098 /* remove old directives if any */
1099 delById(Http::HdrType::CONTENT_RANGE
);
1103 httpHdrContRangePackInto(cr
, &mb
);
1105 addEntry(new HttpHeaderEntry(Http::HdrType::CONTENT_RANGE
, SBuf(), mb
.buf
));
1111 HttpHeader::putRange(const HttpHdrRange
* range
)
1114 /* remove old directives if any */
1115 delById(Http::HdrType::RANGE
);
1119 range
->packInto(&mb
);
1121 addEntry(new HttpHeaderEntry(Http::HdrType::RANGE
, SBuf(), mb
.buf
));
1127 HttpHeader::putSc(HttpHdrSc
*sc
)
1130 /* remove old directives if any */
1131 delById(Http::HdrType::SURROGATE_CONTROL
);
1137 addEntry(new HttpHeaderEntry(Http::HdrType::SURROGATE_CONTROL
, SBuf(), mb
.buf
));
1143 HttpHeader::putWarning(const int code
, const char *const text
)
1146 snprintf(buf
, sizeof(buf
), "%i %s \"%s\"", code
, visible_appname_string
, text
);
1147 putStr(Http::HdrType::WARNING
, buf
);
1150 /* add extension header (these fields are not parsed/analyzed/joined, etc.) */
1152 HttpHeader::putExt(const char *name
, const char *value
)
1154 assert(name
&& value
);
1155 debugs(55, 8, this << " adds ext entry " << name
<< " : " << value
);
1156 addEntry(new HttpHeaderEntry(Http::HdrType::OTHER
, SBuf(name
), value
));
1160 HttpHeader::getInt(Http::HdrType id
) const
1162 assert(any_registered_header(id
));
1163 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftInt
); /* must be of an appropriate type */
1166 if ((e
= findEntry(id
)))
1173 HttpHeader::getInt64(Http::HdrType id
) const
1175 assert(any_registered_header(id
));
1176 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftInt64
); /* must be of an appropriate type */
1179 if ((e
= findEntry(id
)))
1180 return e
->getInt64();
1186 HttpHeader::getTime(Http::HdrType id
) const
1190 assert(any_registered_header(id
));
1191 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftDate_1123
); /* must be of an appropriate type */
1193 if ((e
= findEntry(id
))) {
1194 value
= parse_rfc1123(e
->value
.termedBuf());
1195 httpHeaderNoteParsedEntry(e
->id
, e
->value
, value
< 0);
1201 /* sync with httpHeaderGetLastStr */
1203 HttpHeader::getStr(Http::HdrType id
) const
1206 assert(any_registered_header(id
));
1207 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftStr
); /* must be of an appropriate type */
1209 if ((e
= findEntry(id
))) {
1210 httpHeaderNoteParsedEntry(e
->id
, e
->value
, false); /* no errors are possible */
1211 return e
->value
.termedBuf();
1219 HttpHeader::getLastStr(Http::HdrType id
) const
1222 assert(any_registered_header(id
));
1223 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftStr
); /* must be of an appropriate type */
1225 if ((e
= findLastEntry(id
))) {
1226 httpHeaderNoteParsedEntry(e
->id
, e
->value
, false); /* no errors are possible */
1227 return e
->value
.termedBuf();
1234 HttpHeader::getCc() const
1236 if (!CBIT_TEST(mask
, Http::HdrType::CACHE_CONTROL
))
1238 PROF_start(HttpHeader_getCc
);
1241 getList(Http::HdrType::CACHE_CONTROL
, &s
);
1243 HttpHdrCc
*cc
=new HttpHdrCc();
1245 if (!cc
->parse(s
)) {
1250 ++ HttpHeaderStats
[owner
].ccParsedCount
;
1253 httpHdrCcUpdateStats(cc
, &HttpHeaderStats
[owner
].ccTypeDistr
);
1255 httpHeaderNoteParsedEntry(Http::HdrType::CACHE_CONTROL
, s
, !cc
);
1257 PROF_stop(HttpHeader_getCc
);
1263 HttpHeader::getRange() const
1265 HttpHdrRange
*r
= NULL
;
1267 /* some clients will send "Request-Range" _and_ *matching* "Range"
1268 * who knows, some clients might send Request-Range only;
1269 * this "if" should work correctly in both cases;
1270 * hopefully no clients send mismatched headers! */
1272 if ((e
= findEntry(Http::HdrType::RANGE
)) ||
1273 (e
= findEntry(Http::HdrType::REQUEST_RANGE
))) {
1274 r
= HttpHdrRange::ParseCreate(&e
->value
);
1275 httpHeaderNoteParsedEntry(e
->id
, e
->value
, !r
);
1282 HttpHeader::getSc() const
1284 if (!CBIT_TEST(mask
, Http::HdrType::SURROGATE_CONTROL
))
1289 (void) getList(Http::HdrType::SURROGATE_CONTROL
, &s
);
1291 HttpHdrSc
*sc
= httpHdrScParseCreate(s
);
1293 ++ HttpHeaderStats
[owner
].ccParsedCount
;
1296 sc
->updateStats(&HttpHeaderStats
[owner
].scTypeDistr
);
1298 httpHeaderNoteParsedEntry(Http::HdrType::SURROGATE_CONTROL
, s
, !sc
);
1304 HttpHeader::getContRange() const
1306 HttpHdrContRange
*cr
= NULL
;
1309 if ((e
= findEntry(Http::HdrType::CONTENT_RANGE
))) {
1310 cr
= httpHdrContRangeParseCreate(e
->value
.termedBuf());
1311 httpHeaderNoteParsedEntry(e
->id
, e
->value
, !cr
);
1318 HttpHeader::getAuth(Http::HdrType id
, const char *auth_scheme
) const
1322 assert(auth_scheme
);
1325 if (!field
) /* no authorization field */
1328 l
= strlen(auth_scheme
);
1330 if (!l
|| strncasecmp(field
, auth_scheme
, l
)) /* wrong scheme */
1335 if (!xisspace(*field
)) /* wrong scheme */
1338 /* skip white space */
1339 for (; field
&& xisspace(*field
); ++field
);
1341 if (!*field
) /* no authorization cookie */
1344 static char decodedAuthToken
[8192];
1345 struct base64_decode_ctx ctx
;
1346 base64_decode_init(&ctx
);
1347 size_t decodedLen
= 0;
1348 if (!base64_decode_update(&ctx
, &decodedLen
, reinterpret_cast<uint8_t*>(decodedAuthToken
), strlen(field
), field
) ||
1349 !base64_decode_final(&ctx
)) {
1352 decodedAuthToken
[decodedLen
] = '\0';
1353 return decodedAuthToken
;
1357 HttpHeader::getETag(Http::HdrType id
) const
1359 ETag etag
= {NULL
, -1};
1361 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftETag
); /* must be of an appropriate type */
1363 if ((e
= findEntry(id
)))
1364 etagParseInit(&etag
, e
->value
.termedBuf());
1370 HttpHeader::getTimeOrTag(Http::HdrType id
) const
1374 assert(Http::HeaderLookupTable
.lookup(id
).type
== Http::HdrFieldType::ftDate_1123_or_ETag
); /* must be of an appropriate type */
1375 memset(&tot
, 0, sizeof(tot
));
1377 if ((e
= findEntry(id
))) {
1378 const char *str
= e
->value
.termedBuf();
1379 /* try as an ETag */
1381 if (etagParseInit(&tot
.tag
, str
)) {
1382 tot
.valid
= tot
.tag
.str
!= NULL
;
1385 /* or maybe it is time? */
1386 tot
.time
= parse_rfc1123(str
);
1387 tot
.valid
= tot
.time
>= 0;
1392 assert(tot
.time
< 0 || !tot
.tag
.str
); /* paranoid */
1400 HttpHeaderEntry::HttpHeaderEntry(Http::HdrType anId
, const SBuf
&aName
, const char *aValue
)
1402 assert(any_HdrType_enum_value(anId
));
1405 if (id
!= Http::HdrType::OTHER
)
1406 name
= Http::HeaderLookupTable
.lookup(id
).name
;
1412 if (id
!= Http::HdrType::BAD_HDR
)
1413 ++ headerStatsTable
[id
].aliveCount
;
1415 debugs(55, 9, "created HttpHeaderEntry " << this << ": '" << name
<< " : " << value
);
1418 HttpHeaderEntry::~HttpHeaderEntry()
1420 debugs(55, 9, "destroying entry " << this << ": '" << name
<< ": " << value
<< "'");
1422 if (id
!= Http::HdrType::BAD_HDR
) {
1423 assert(headerStatsTable
[id
].aliveCount
);
1424 -- headerStatsTable
[id
].aliveCount
;
1425 id
= Http::HdrType::BAD_HDR
; // it already is BAD_HDR, no sense in resetting it
1430 /* parses and inits header entry, returns true/false */
1432 HttpHeaderEntry::parse(const char *field_start
, const char *field_end
)
1434 /* note: name_start == field_start */
1435 const char *name_end
= (const char *)memchr(field_start
, ':', field_end
- field_start
);
1436 int name_len
= name_end
? name_end
- field_start
:0;
1437 const char *value_start
= field_start
+ name_len
+ 1; /* skip ':' */
1438 /* note: value_end == field_end */
1440 ++ HeaderEntryParsedCount
;
1442 /* do we have a valid field name within this field? */
1444 if (!name_len
|| name_end
> field_end
)
1447 if (name_len
> 65534) {
1448 /* String must be LESS THAN 64K and it adds a terminating NULL */
1449 debugs(55, DBG_IMPORTANT
, "WARNING: ignoring header name of " << name_len
<< " bytes");
1453 if (Config
.onoff
.relaxed_header_parser
&& xisspace(field_start
[name_len
- 1])) {
1454 debugs(55, Config
.onoff
.relaxed_header_parser
<= 0 ? 1 : 2,
1455 "NOTICE: Whitespace after header name in '" << getStringPrefix(field_start
, field_end
-field_start
) << "'");
1457 while (name_len
> 0 && xisspace(field_start
[name_len
- 1]))
1464 /* now we know we can parse it */
1466 debugs(55, 9, "parsing HttpHeaderEntry: near '" << getStringPrefix(field_start
, field_end
-field_start
) << "'");
1468 /* is it a "known" field? */
1469 Http::HdrType id
= Http::HeaderLookupTable
.lookup(field_start
,name_len
).id
;
1470 debugs(55, 9, "got hdr-id=" << id
);
1476 if (id
== Http::HdrType::BAD_HDR
)
1477 id
= Http::HdrType::OTHER
;
1479 /* set field name */
1480 if (id
== Http::HdrType::OTHER
)
1481 theName
.append(field_start
, name_len
);
1483 theName
= Http::HeaderLookupTable
.lookup(id
).name
;
1485 /* trim field value */
1486 while (value_start
< field_end
&& xisspace(*value_start
))
1489 while (value_start
< field_end
&& xisspace(field_end
[-1]))
1492 if (field_end
- value_start
> 65534) {
1493 /* String must be LESS THAN 64K and it adds a terminating NULL */
1494 debugs(55, DBG_IMPORTANT
, "WARNING: ignoring '" << theName
<< "' header of " << (field_end
- value_start
) << " bytes");
1498 /* set field value */
1499 value
.limitInit(value_start
, field_end
- value_start
);
1501 if (id
!= Http::HdrType::BAD_HDR
)
1502 ++ headerStatsTable
[id
].seenCount
;
1504 debugs(55, 9, "parsed HttpHeaderEntry: '" << theName
<< ": " << value
<< "'");
1506 return new HttpHeaderEntry(id
, theName
, value
.termedBuf());
1510 HttpHeaderEntry::clone() const
1512 return new HttpHeaderEntry(id
, name
, value
.termedBuf());
1516 HttpHeaderEntry::packInto(Packable
* p
) const
1519 p
->append(name
.rawContent(), name
.length());
1521 p
->append(value
.rawBuf(), value
.size());
1522 p
->append("\r\n", 2);
1526 HttpHeaderEntry::getInt() const
1529 int ok
= httpHeaderParseInt(value
.termedBuf(), &val
);
1530 httpHeaderNoteParsedEntry(id
, value
, ok
== 0);
1531 /* XXX: Should we check ok - ie
1532 * return ok ? -1 : value;
1538 HttpHeaderEntry::getInt64() const
1541 const bool ok
= httpHeaderParseOffset(value
.termedBuf(), &val
);
1542 httpHeaderNoteParsedEntry(id
, value
, !ok
);
1543 return val
; // remains -1 if !ok (XXX: bad method API)
1547 httpHeaderNoteParsedEntry(Http::HdrType id
, String
const &context
, bool error
)
1549 if (id
!= Http::HdrType::BAD_HDR
)
1550 ++ headerStatsTable
[id
].parsCount
;
1553 if (id
!= Http::HdrType::BAD_HDR
)
1554 ++ headerStatsTable
[id
].errCount
;
1555 debugs(55, 2, "cannot parse hdr field: '" << Http::HeaderLookupTable
.lookup(id
).name
<< ": " << context
<< "'");
1563 /* tmp variable used to pass stat info to dumpers */
1564 extern const HttpHeaderStat
*dump_stat
; /* argh! */
1565 const HttpHeaderStat
*dump_stat
= NULL
;
1568 httpHeaderFieldStatDumper(StoreEntry
* sentry
, int, double val
, double, int count
)
1570 const int id
= static_cast<int>(val
);
1571 const bool valid_id
= Http::any_valid_header(static_cast<Http::HdrType
>(id
));
1572 const char *name
= valid_id
? Http::HeaderLookupTable
.lookup(static_cast<Http::HdrType
>(id
)).name
: "INVALID";
1573 int visible
= count
> 0;
1574 /* for entries with zero count, list only those that belong to current type of message */
1576 if (!visible
&& valid_id
&& dump_stat
->owner_mask
)
1577 visible
= CBIT_TEST(*dump_stat
->owner_mask
, id
);
1580 storeAppendPrintf(sentry
, "%2d\t %-20s\t %5d\t %6.2f\n",
1581 id
, name
, count
, xdiv(count
, dump_stat
->busyDestroyedCount
));
1585 httpHeaderFldsPerHdrDumper(StoreEntry
* sentry
, int idx
, double val
, double, int count
)
1588 storeAppendPrintf(sentry
, "%2d\t %5d\t %5d\t %6.2f\n",
1589 idx
, (int) val
, count
,
1590 xpercent(count
, dump_stat
->destroyedCount
));
1594 httpHeaderStatDump(const HttpHeaderStat
* hs
, StoreEntry
* e
)
1600 storeAppendPrintf(e
, "\nHeader Stats: %s\n", hs
->label
);
1601 storeAppendPrintf(e
, "\nField type distribution\n");
1602 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1603 "id", "name", "count", "#/header");
1604 hs
->fieldTypeDistr
.dump(e
, httpHeaderFieldStatDumper
);
1605 storeAppendPrintf(e
, "\nCache-control directives distribution\n");
1606 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1607 "id", "name", "count", "#/cc_field");
1608 hs
->ccTypeDistr
.dump(e
, httpHdrCcStatDumper
);
1609 storeAppendPrintf(e
, "\nSurrogate-control directives distribution\n");
1610 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1611 "id", "name", "count", "#/sc_field");
1612 hs
->scTypeDistr
.dump(e
, httpHdrScStatDumper
);
1613 storeAppendPrintf(e
, "\nNumber of fields per header distribution\n");
1614 storeAppendPrintf(e
, "%2s\t %-5s\t %5s\t %6s\n",
1615 "id", "#flds", "count", "%total");
1616 hs
->hdrUCountDistr
.dump(e
, httpHeaderFldsPerHdrDumper
);
1617 storeAppendPrintf(e
, "\n");
1622 httpHeaderStoreReport(StoreEntry
* e
)
1627 HttpHeaderStats
[0].parsedCount
=
1628 HttpHeaderStats
[hoRequest
].parsedCount
+ HttpHeaderStats
[hoReply
].parsedCount
;
1629 HttpHeaderStats
[0].ccParsedCount
=
1630 HttpHeaderStats
[hoRequest
].ccParsedCount
+ HttpHeaderStats
[hoReply
].ccParsedCount
;
1631 HttpHeaderStats
[0].destroyedCount
=
1632 HttpHeaderStats
[hoRequest
].destroyedCount
+ HttpHeaderStats
[hoReply
].destroyedCount
;
1633 HttpHeaderStats
[0].busyDestroyedCount
=
1634 HttpHeaderStats
[hoRequest
].busyDestroyedCount
+ HttpHeaderStats
[hoReply
].busyDestroyedCount
;
1636 for (i
= 1; i
< HttpHeaderStatCount
; ++i
) {
1637 httpHeaderStatDump(HttpHeaderStats
+ i
, e
);
1640 /* field stats for all messages */
1641 storeAppendPrintf(e
, "\nHttp Fields Stats (replies and requests)\n");
1643 storeAppendPrintf(e
, "%2s\t %-25s\t %5s\t %6s\t %6s\n",
1644 "id", "name", "#alive", "%err", "%repeat");
1646 // scan heaaderTable and output
1647 for (auto h
: WholeEnum
<Http::HdrType
>()) {
1648 auto stats
= headerStatsTable
[h
];
1649 storeAppendPrintf(e
, "%2d\t %-25s\t %5d\t %6.3f\t %6.3f\n",
1650 Http::HeaderLookupTable
.lookup(h
).id
,
1651 Http::HeaderLookupTable
.lookup(h
).name
,
1653 xpercent(stats
.errCount
, stats
.parsCount
),
1654 xpercent(stats
.repCount
, stats
.seenCount
));
1657 storeAppendPrintf(e
, "Headers Parsed: %d + %d = %d\n",
1658 HttpHeaderStats
[hoRequest
].parsedCount
,
1659 HttpHeaderStats
[hoReply
].parsedCount
,
1660 HttpHeaderStats
[0].parsedCount
);
1661 storeAppendPrintf(e
, "Hdr Fields Parsed: %d\n", HeaderEntryParsedCount
);
1665 HttpHeader::hasListMember(Http::HdrType id
, const char *member
, const char separator
) const
1668 const char *pos
= NULL
;
1671 int mlen
= strlen(member
);
1673 assert(any_registered_header(id
));
1675 String
header (getStrOrList(id
));
1677 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1678 if (strncasecmp(item
, member
, mlen
) == 0
1679 && (item
[mlen
] == '=' || item
[mlen
] == separator
|| item
[mlen
] == ';' || item
[mlen
] == '\0')) {
1689 HttpHeader::hasByNameListMember(const char *name
, const char *member
, const char separator
) const
1692 const char *pos
= NULL
;
1695 int mlen
= strlen(member
);
1699 String
header (getByName(name
));
1701 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1702 if (strncasecmp(item
, member
, mlen
) == 0
1703 && (item
[mlen
] == '=' || item
[mlen
] == separator
|| item
[mlen
] == ';' || item
[mlen
] == '\0')) {
1713 HttpHeader::removeHopByHopEntries()
1715 removeConnectionHeaderEntries();
1717 const HttpHeaderEntry
*e
;
1718 HttpHeaderPos pos
= HttpHeaderInitPos
;
1719 int headers_deleted
= 0;
1720 while ((e
= getEntry(&pos
))) {
1721 Http::HdrType id
= e
->id
;
1722 if (Http::HeaderLookupTable
.lookup(id
).hopbyhop
) {
1723 delAt(pos
, headers_deleted
);
1730 HttpHeader::removeConnectionHeaderEntries()
1732 if (has(Http::HdrType::CONNECTION
)) {
1733 /* anything that matches Connection list member will be deleted */
1734 String strConnection
;
1736 (void) getList(Http::HdrType::CONNECTION
, &strConnection
);
1737 const HttpHeaderEntry
*e
;
1738 HttpHeaderPos pos
= HttpHeaderInitPos
;
1740 * think: on-average-best nesting of the two loops (hdrEntry
1741 * and strListItem) @?@
1744 * maybe we should delete standard stuff ("keep-alive","close")
1745 * from strConnection first?
1748 int headers_deleted
= 0;
1749 while ((e
= getEntry(&pos
))) {
1750 if (strListIsMember(&strConnection
, e
->name
, ','))
1751 delAt(pos
, headers_deleted
);
1753 if (headers_deleted
)