2 * Copyright (C) 1996-2015 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/LookupTable.h"
15 #include "HttpHdrCc.h"
16 #include "HttpHdrContRange.h"
17 #include "HttpHdrSc.h"
18 #include "HttpHeader.h"
19 #include "HttpHeaderFieldInfo.h"
20 #include "HttpHeaderStat.h"
21 #include "HttpHeaderTools.h"
23 #include "mgr/Registration.h"
24 #include "profiler/Profiler.h"
26 #include "SquidConfig.h"
27 #include "SquidString.h"
31 #include "TimeOrTag.h"
36 /* XXX: the whole set of API managing the entries vector should be rethought
37 * after the parse4r-ng effort is complete.
41 * On naming conventions:
43 * HTTP/1.1 defines message-header as
45 * message-header = field-name ":" [ field-value ] CRLF
47 * field-value = *( field-content | LWS )
49 * HTTP/1.1 does not give a name name a group of all message-headers in a message.
50 * Squid 1.1 seems to refer to that group _plus_ start-line as "headers".
52 * HttpHeader is an object that represents all message-headers in a message.
53 * HttpHeader does not manage start-line.
55 * HttpHeader is implemented as a collection of header "entries".
56 * An entry is a (field_id, field_name, field_value) triplet.
60 * local constants and vars
64 * DONE 1. shift HDR_BAD_HDR to end of enum
65 * DONE 2. shift headers data array to http/RegistredHeaders.cc
66 * DONE 3. creatign LookupTable object from teh enum and array
67 * (with HDR_BAD_HDR as invalid value)
68 * DONE 4. replacing httpHeaderIdByName() uses with the lookup table
69 * 5. merge HDR_BAD_HDR and HDR_ENUM_END into one thing
70 * DONE 6. replacing httpHeaderNameById with direct array lookups
71 * 7. being looking at the other arrays removal
75 LookupTable
<http_hdr_type
, HeaderTableRecord
> headerLookupTable(HDR_BAD_HDR
, headerTable
);
76 std::vector
<HttpHeaderFieldStat
> headerStatsTable(HDR_OTHER
+1);
79 * headers with field values defined as #(values) in HTTP/1.1
80 * Headers that are currently not recognized, are commented out.
82 static HttpHeaderMask ListHeadersMask
; /* set run-time using ListHeadersArr */
83 static http_hdr_type ListHeadersArr
[] = {
100 HDR_PROXY_CONNECTION
,
102 HDR_TRANSFER_ENCODING
,
107 HDR_WWW_AUTHENTICATE
,
108 HDR_AUTHENTICATION_INFO
,
109 HDR_PROXY_AUTHENTICATION_INFO
,
110 /* HDR_TE, HDR_TRAILER */
111 #if X_ACCELERATOR_VARY
112 HDR_X_ACCELERATOR_VARY
,
117 HDR_SURROGATE_CAPABILITY
,
118 HDR_SURROGATE_CONTROL
,
123 /* general-headers */
124 static http_hdr_type GeneralHeadersArr
[] = {
132 HDR_PROXY_CONNECTION
,
133 HDR_TRANSFER_ENCODING
,
140 static http_hdr_type EntityHeadersArr
[] = {
143 HDR_CONTENT_ENCODING
,
144 HDR_CONTENT_LANGUAGE
,
146 HDR_CONTENT_LOCATION
,
157 /* request-only headers */
158 static HttpHeaderMask RequestHeadersMask
; /* set run-time using RequestHeaders */
159 static http_hdr_type RequestHeadersArr
[] = {
170 HDR_IF_MODIFIED_SINCE
,
173 HDR_IF_UNMODIFIED_SINCE
,
176 HDR_PROXY_AUTHORIZATION
,
182 HDR_SURROGATE_CAPABILITY
185 /* reply-only headers */
186 static HttpHeaderMask ReplyHeadersMask
; /* set run-time using ReplyHeaders */
187 static http_hdr_type ReplyHeadersArr
[] = {
193 HDR_PROXY_AUTHENTICATE
,
201 HDR_WWW_AUTHENTICATE
,
205 #if X_ACCELERATOR_VARY
206 HDR_X_ACCELERATOR_VARY
,
212 HDR_SURROGATE_CONTROL
215 /* hop-by-hop headers */
216 static HttpHeaderMask HopByHopHeadersMask
;
217 static http_hdr_type HopByHopHeadersArr
[] = {
218 HDR_ALTERNATE_PROTOCOL
,
222 /*HDR_PROXY_AUTHENTICATE, // removal handled specially for peer login */
223 HDR_PROXY_AUTHORIZATION
,
226 HDR_TRANSFER_ENCODING
,
231 /* header accounting */
232 // NP: keep in sync with enum http_hdr_owner_type
233 static HttpHeaderStat HttpHeaderStats
[] = {
234 HttpHeaderStat(/*hoNone*/ "all", NULL
),
236 HttpHeaderStat(/*hoHtcpReply*/ "HTCP reply", &ReplyHeadersMask
),
238 HttpHeaderStat(/*hoRequest*/ "request", &RequestHeadersMask
),
239 HttpHeaderStat(/*hoReply*/ "reply", &ReplyHeadersMask
)
245 static int HttpHeaderStatCount
= countof(HttpHeaderStats
);
247 static int HeaderEntryParsedCount
= 0;
250 * forward declarations and local routines
254 #define assert_eid(id) assert((id) >= 0 && (id) < HDR_ENUM_END)
256 static void httpHeaderNoteParsedEntry(http_hdr_type id
, String
const &value
, int error
);
258 static void httpHeaderStatDump(const HttpHeaderStat
* hs
, StoreEntry
* e
);
260 /** store report about current header usage and other stats */
261 static void httpHeaderStoreReport(StoreEntry
* e
);
264 * Module initialization routines
268 httpHeaderRegisterWithCacheManager(void)
270 Mgr::RegisterAction("http_headers",
271 "HTTP Header Statistics",
272 httpHeaderStoreReport
, 0, 1);
276 httpHeaderInitModule(void)
278 /* check that we have enough space for masks */
279 assert(8 * sizeof(HttpHeaderMask
) >= HDR_ENUM_END
);
281 // check invariant: for each index in headerTable, (int)headerTable[index] = index
282 for (int i
= 0; headerTable
[i
].name
; ++i
)
283 assert(headerTable
[i
].id
== i
);
285 // use headerLookupTable in place of Headers
288 httpHeaderMaskInit(&ListHeadersMask
, 0);
289 httpHeaderCalcMask(&ListHeadersMask
, ListHeadersArr
, countof(ListHeadersArr
));
291 httpHeaderMaskInit(&ReplyHeadersMask
, 0);
292 httpHeaderCalcMask(&ReplyHeadersMask
, ReplyHeadersArr
, countof(ReplyHeadersArr
));
293 httpHeaderCalcMask(&ReplyHeadersMask
, GeneralHeadersArr
, countof(GeneralHeadersArr
));
294 httpHeaderCalcMask(&ReplyHeadersMask
, EntityHeadersArr
, countof(EntityHeadersArr
));
296 httpHeaderMaskInit(&RequestHeadersMask
, 0);
297 httpHeaderCalcMask(&RequestHeadersMask
, RequestHeadersArr
, countof(RequestHeadersArr
));
298 httpHeaderCalcMask(&RequestHeadersMask
, GeneralHeadersArr
, countof(GeneralHeadersArr
));
299 httpHeaderCalcMask(&RequestHeadersMask
, EntityHeadersArr
, countof(EntityHeadersArr
));
301 httpHeaderMaskInit(&HopByHopHeadersMask
, 0);
302 httpHeaderCalcMask(&HopByHopHeadersMask
, HopByHopHeadersArr
, countof(HopByHopHeadersArr
));
304 /* header stats initialized by class constructor */
305 assert(HttpHeaderStatCount
== hoReply
+ 1);
307 /* init dependent modules */
308 httpHdrCcInitModule();
309 httpHdrScInitModule();
311 httpHeaderRegisterWithCacheManager();
315 httpHeaderCleanModule(void)
317 httpHdrCcCleanModule();
318 httpHdrScCleanModule();
322 * HttpHeader Implementation
325 HttpHeader::HttpHeader() : owner (hoNone
), len (0)
327 httpHeaderMaskInit(&mask
, 0);
330 HttpHeader::HttpHeader(const http_hdr_owner_type anOwner
): owner(anOwner
), len(0)
332 assert(anOwner
> hoNone
&& anOwner
< hoEnd
);
333 debugs(55, 7, "init-ing hdr: " << this << " owner: " << owner
);
334 httpHeaderMaskInit(&mask
, 0);
337 HttpHeader::HttpHeader(const HttpHeader
&other
): owner(other
.owner
), len(other
.len
)
339 httpHeaderMaskInit(&mask
, 0);
340 update(&other
, NULL
); // will update the mask as well
343 HttpHeader::~HttpHeader()
349 HttpHeader::operator =(const HttpHeader
&other
)
351 if (this != &other
) {
352 // we do not really care, but the caller probably does
353 assert(owner
== other
.owner
);
355 update(&other
, NULL
); // will update the mask as well
365 assert(owner
> hoNone
&& owner
< hoEnd
);
366 debugs(55, 7, "cleaning hdr: " << this << " owner: " << owner
);
368 PROF_start(HttpHeaderClean
);
370 if (owner
<= hoReply
) {
372 * An unfortunate bug. The entries array is initialized
373 * such that count is set to zero. httpHeaderClean() seems to
374 * be called both when 'hdr' is created, and destroyed. Thus,
375 * we accumulate a large number of zero counts for 'hdr' before
376 * it is ever used. Can't think of a good way to fix it, except
377 * adding a state variable that indicates whether or not 'hdr'
378 * has been used. As a hack, just never count zero-sized header
381 if (!entries
.empty())
382 HttpHeaderStats
[owner
].hdrUCountDistr
.count(entries
.size());
384 ++ HttpHeaderStats
[owner
].destroyedCount
;
386 HttpHeaderStats
[owner
].busyDestroyedCount
+= entries
.size() > 0;
387 } // if (owner <= hoReply)
389 for (std::vector
<HttpHeaderEntry
*>::iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
390 HttpHeaderEntry
*e
= *i
;
393 if (e
->id
< 0 || e
->id
>= HDR_ENUM_END
) {
394 debugs(55, DBG_CRITICAL
, "BUG: invalid entry (" << e
->id
<< "). Ignored.");
396 if (owner
<= hoReply
)
397 HttpHeaderStats
[owner
].fieldTypeDistr
.count(e
->id
);
403 httpHeaderMaskInit(&mask
, 0);
405 PROF_stop(HttpHeaderClean
);
408 /* append entries (also see httpHeaderUpdate) */
410 HttpHeader::append(const HttpHeader
* src
)
412 const HttpHeaderEntry
*e
;
413 HttpHeaderPos pos
= HttpHeaderInitPos
;
416 debugs(55, 7, "appending hdr: " << this << " += " << src
);
418 while ((e
= src
->getEntry(&pos
))) {
419 addEntry(e
->clone());
423 /* use fresh entries to replace old ones */
425 httpHeaderUpdate(HttpHeader
* old
, const HttpHeader
* fresh
, const HttpHeaderMask
* denied_mask
)
428 old
->update (fresh
, denied_mask
);
432 HttpHeader::update (HttpHeader
const *fresh
, HttpHeaderMask
const *denied_mask
)
434 const HttpHeaderEntry
*e
;
435 HttpHeaderPos pos
= HttpHeaderInitPos
;
437 assert(this != fresh
);
439 while ((e
= fresh
->getEntry(&pos
))) {
440 /* deny bad guys (ok to check for HDR_OTHER) here */
442 if (denied_mask
&& CBIT_TEST(*denied_mask
, e
->id
))
445 if (e
->id
!= HDR_OTHER
)
448 delByName(e
->name
.termedBuf());
451 pos
= HttpHeaderInitPos
;
452 while ((e
= fresh
->getEntry(&pos
))) {
453 /* deny bad guys (ok to check for HDR_OTHER) here */
455 if (denied_mask
&& CBIT_TEST(*denied_mask
, e
->id
))
458 debugs(55, 7, "Updating header '" << headerTable
[e
->id
].name
<< "' in cached entry");
460 addEntry(e
->clone());
464 /* just handy in parsing: resets and returns false */
473 HttpHeader::parse(const char *header_start
, size_t hdrLen
)
475 const char *field_ptr
= header_start
;
476 const char *header_end
= header_start
+ hdrLen
; // XXX: remove
477 HttpHeaderEntry
*e
, *e2
;
478 int warnOnError
= (Config
.onoff
.relaxed_header_parser
<= 0 ? DBG_IMPORTANT
: 2);
480 PROF_start(HttpHeaderParse
);
482 assert(header_start
&& header_end
);
483 debugs(55, 7, "parsing hdr: (" << this << ")" << std::endl
<< getStringPrefix(header_start
, hdrLen
));
484 ++ HttpHeaderStats
[owner
].parsedCount
;
487 if ((nulpos
= (char*)memchr(header_start
, '\0', hdrLen
))) {
488 debugs(55, DBG_IMPORTANT
, "WARNING: HTTP header contains NULL characters {" <<
489 getStringPrefix(header_start
, nulpos
-header_start
) << "}\nNULL\n{" << getStringPrefix(nulpos
+1, hdrLen
-(nulpos
-header_start
)-1));
490 PROF_stop(HttpHeaderParse
);
494 /* common format headers are "<name>:[ws]<value>" lines delimited by <CRLF>.
495 * continuation lines start with a (single) space or tab */
496 while (field_ptr
< header_end
) {
497 const char *field_start
= field_ptr
;
498 const char *field_end
;
501 const char *this_line
= field_ptr
;
502 field_ptr
= (const char *)memchr(field_ptr
, '\n', header_end
- field_ptr
);
506 PROF_stop(HttpHeaderParse
);
510 field_end
= field_ptr
;
512 ++field_ptr
; /* Move to next line */
514 if (field_end
> this_line
&& field_end
[-1] == '\r') {
515 --field_end
; /* Ignore CR LF */
517 if (owner
== hoRequest
&& field_end
> this_line
) {
519 for (const char *p
= this_line
; p
< field_end
&& cr_only
; ++p
) {
524 debugs(55, DBG_IMPORTANT
, "SECURITY WARNING: Rejecting HTTP request with a CR+ "
525 "header field to prevent request smuggling attacks: {" <<
526 getStringPrefix(header_start
, hdrLen
) << "}");
527 PROF_stop(HttpHeaderParse
);
533 /* Barf on stray CR characters */
534 if (memchr(this_line
, '\r', field_end
- this_line
)) {
535 debugs(55, warnOnError
, "WARNING: suspicious CR characters in HTTP header {" <<
536 getStringPrefix(field_start
, field_end
-field_start
) << "}");
538 if (Config
.onoff
.relaxed_header_parser
) {
539 char *p
= (char *) this_line
; /* XXX Warning! This destroys original header content and violates specifications somewhat */
541 while ((p
= (char *)memchr(p
, '\r', field_end
- p
)) != NULL
) {
546 PROF_stop(HttpHeaderParse
);
551 if (this_line
+ 1 == field_end
&& this_line
> field_start
) {
552 debugs(55, warnOnError
, "WARNING: Blank continuation line in HTTP header {" <<
553 getStringPrefix(header_start
, hdrLen
) << "}");
554 PROF_stop(HttpHeaderParse
);
557 } while (field_ptr
< header_end
&& (*field_ptr
== ' ' || *field_ptr
== '\t'));
559 if (field_start
== field_end
) {
560 if (field_ptr
< header_end
) {
561 debugs(55, warnOnError
, "WARNING: unparseable HTTP header field near {" <<
562 getStringPrefix(field_start
, hdrLen
-(field_start
-header_start
)) << "}");
563 PROF_stop(HttpHeaderParse
);
567 break; /* terminating blank line */
570 if ((e
= HttpHeaderEntry::parse(field_start
, field_end
)) == NULL
) {
571 debugs(55, warnOnError
, "WARNING: unparseable HTTP header field {" <<
572 getStringPrefix(field_start
, field_end
-field_start
) << "}");
573 debugs(55, warnOnError
, " in {" << getStringPrefix(header_start
, hdrLen
) << "}");
575 if (Config
.onoff
.relaxed_header_parser
)
578 PROF_stop(HttpHeaderParse
);
582 if (e
->id
== HDR_CONTENT_LENGTH
&& (e2
= findEntry(e
->id
)) != NULL
) {
583 if (e
->value
!= e2
->value
) {
585 debugs(55, warnOnError
, "WARNING: found two conflicting content-length headers in {" <<
586 getStringPrefix(header_start
, hdrLen
) << "}");
588 if (!Config
.onoff
.relaxed_header_parser
) {
590 PROF_stop(HttpHeaderParse
);
594 if (!httpHeaderParseOffset(e
->value
.termedBuf(), &l1
)) {
595 debugs(55, DBG_IMPORTANT
, "WARNING: Unparseable content-length '" << e
->value
<< "'");
598 } else if (!httpHeaderParseOffset(e2
->value
.termedBuf(), &l2
)) {
599 debugs(55, DBG_IMPORTANT
, "WARNING: Unparseable content-length '" << e2
->value
<< "'");
601 } else if (l1
> l2
) {
608 debugs(55, warnOnError
, "NOTICE: found double content-length header");
611 if (Config
.onoff
.relaxed_header_parser
)
614 PROF_stop(HttpHeaderParse
);
619 if (e
->id
== HDR_OTHER
&& stringHasWhitespace(e
->name
.termedBuf())) {
620 debugs(55, warnOnError
, "WARNING: found whitespace in HTTP header name {" <<
621 getStringPrefix(field_start
, field_end
-field_start
) << "}");
623 if (!Config
.onoff
.relaxed_header_parser
) {
625 PROF_stop(HttpHeaderParse
);
634 // RFC 2616 section 4.4: ignore Content-Length with Transfer-Encoding
635 delById(HDR_CONTENT_LENGTH
);
638 PROF_stop(HttpHeaderParse
);
639 return 1; /* even if no fields where found, it is a valid header */
642 /* packs all the entries using supplied packer */
644 HttpHeader::packInto(Packable
* p
, bool mask_sensitive_info
) const
646 HttpHeaderPos pos
= HttpHeaderInitPos
;
647 const HttpHeaderEntry
*e
;
649 debugs(55, 7, this << " into " << p
<<
650 (mask_sensitive_info
? " while masking" : ""));
651 /* pack all entries one by one */
652 while ((e
= getEntry(&pos
))) {
653 if (!mask_sensitive_info
) {
658 bool maskThisEntry
= false;
660 case HDR_AUTHORIZATION
:
661 case HDR_PROXY_AUTHORIZATION
:
662 maskThisEntry
= true;
665 case HDR_FTP_ARGUMENTS
:
666 if (const HttpHeaderEntry
*cmd
= findEntry(HDR_FTP_COMMAND
))
667 maskThisEntry
= (cmd
->value
== "PASS");
674 p
->append(e
->name
.rawBuf(), e
->name
.size());
675 p
->append(": ** NOT DISPLAYED **\r\n", 23);
681 /* Pack in the "special" entries */
686 /* returns next valid entry */
688 HttpHeader::getEntry(HttpHeaderPos
* pos
) const
691 assert(*pos
>= HttpHeaderInitPos
&& *pos
< static_cast<ssize_t
>(entries
.size()));
693 for (++(*pos
); *pos
< static_cast<ssize_t
>(entries
.size()); ++(*pos
)) {
695 return static_cast<HttpHeaderEntry
*>(entries
[*pos
]);
702 * returns a pointer to a specified entry if any
703 * note that we return one entry so it does not make much sense to ask for
707 HttpHeader::findEntry(http_hdr_type id
) const
709 HttpHeaderPos pos
= HttpHeaderInitPos
;
712 assert(!CBIT_TEST(ListHeadersMask
, id
));
714 /* check mask first */
716 if (!CBIT_TEST(mask
, id
))
719 /* looks like we must have it, do linear search */
720 while ((e
= getEntry(&pos
))) {
725 /* hm.. we thought it was there, but it was not found */
728 return NULL
; /* not reached */
732 * same as httpHeaderFindEntry
735 HttpHeader::findLastEntry(http_hdr_type id
) const
737 HttpHeaderPos pos
= HttpHeaderInitPos
;
739 HttpHeaderEntry
*result
= NULL
;
741 assert(!CBIT_TEST(ListHeadersMask
, id
));
743 /* check mask first */
745 if (!CBIT_TEST(mask
, id
))
748 /* looks like we must have it, do linear search */
749 while ((e
= getEntry(&pos
))) {
754 assert(result
); /* must be there! */
759 * deletes all fields with a given name if any, returns #fields deleted;
762 HttpHeader::delByName(const char *name
)
765 HttpHeaderPos pos
= HttpHeaderInitPos
;
767 httpHeaderMaskInit(&mask
, 0); /* temporal inconsistency */
768 debugs(55, 9, "deleting '" << name
<< "' fields in hdr " << this);
770 while ((e
= getEntry(&pos
))) {
771 if (!e
->name
.caseCmp(name
))
774 CBIT_SET(mask
, e
->id
);
780 /* deletes all entries with a given id, returns the #entries deleted */
782 HttpHeader::delById(http_hdr_type id
)
785 HttpHeaderPos pos
= HttpHeaderInitPos
;
787 debugs(55, 8, this << " del-by-id " << id
);
789 assert(id
!= HDR_OTHER
); /* does not make sense */
791 if (!CBIT_TEST(mask
, id
))
794 while ((e
= getEntry(&pos
))) {
805 * deletes an entry at pos and leaves a gap; leaving a gap makes it
806 * possible to iterate(search) and delete fields at the same time
807 * NOTE: Does not update the header mask. Caller must follow up with
808 * a call to refreshMask() if headers_deleted was incremented.
811 HttpHeader::delAt(HttpHeaderPos pos
, int &headers_deleted
)
814 assert(pos
>= HttpHeaderInitPos
&& pos
< static_cast<ssize_t
>(entries
.size()));
815 e
= static_cast<HttpHeaderEntry
*>(entries
[pos
]);
817 /* decrement header length, allow for ": " and crlf */
818 len
-= e
->name
.size() + 2 + e
->value
.size() + 2;
825 * Compacts the header storage
828 HttpHeader::compact()
830 // TODO: optimize removal, or possibly make it so that's not needed.
831 std::vector
<HttpHeaderEntry
*>::iterator newend
;
832 newend
= std::remove(entries
.begin(), entries
.end(), static_cast<HttpHeaderEntry
*>(NULL
));
833 entries
.resize(newend
-entries
.begin());
837 * Refreshes the header mask. Required after delAt() calls.
840 HttpHeader::refreshMask()
842 httpHeaderMaskInit(&mask
, 0);
843 debugs(55, 7, "refreshing the mask in hdr " << this);
844 HttpHeaderPos pos
= HttpHeaderInitPos
;
845 while (HttpHeaderEntry
*e
= getEntry(&pos
)) {
846 CBIT_SET(mask
, e
->id
);
851 * does not call e->clone() so one should not reuse "*e"
854 HttpHeader::addEntry(HttpHeaderEntry
* e
)
858 assert(e
->name
.size());
860 debugs(55, 7, this << " adding entry: " << e
->id
<< " at " << entries
.size());
862 if (CBIT_TEST(mask
, e
->id
)) {
863 ++ headerStatsTable
[e
->id
].repCount
;
865 CBIT_SET(mask
, e
->id
);
868 entries
.push_back(e
);
870 /* increment header length, allow for ": " and crlf */
871 len
+= e
->name
.size() + 2 + e
->value
.size() + 2;
875 * does not call e->clone() so one should not reuse "*e"
878 HttpHeader::insertEntry(HttpHeaderEntry
* e
)
883 debugs(55, 7, this << " adding entry: " << e
->id
<< " at " << entries
.size());
885 if (CBIT_TEST(mask
, e
->id
)) {
886 ++ headerStatsTable
[e
->id
].repCount
; //TODO: use operator[] ?
888 CBIT_SET(mask
, e
->id
);
891 entries
.insert(entries
.begin(),e
);
893 /* increment header length, allow for ": " and crlf */
894 len
+= e
->name
.size() + 2 + e
->value
.size() + 2;
898 HttpHeader::getList(http_hdr_type id
, String
*s
) const
901 HttpHeaderPos pos
= HttpHeaderInitPos
;
902 debugs(55, 9, this << " joining for id " << id
);
903 /* only fields from ListHeaders array can be "listed" */
904 assert(CBIT_TEST(ListHeadersMask
, id
));
906 if (!CBIT_TEST(mask
, id
))
909 while ((e
= getEntry(&pos
))) {
911 strListAdd(s
, e
->value
.termedBuf(), ',');
915 * note: we might get an empty (size==0) string if there was an "empty"
916 * header. This results in an empty length String, which may have a NULL
919 /* temporary warning: remove it? (Is it useful for diagnostics ?) */
921 debugs(55, 3, "empty list header: " << headerTable
[id
].name
<< "(" << id
<< ")");
923 debugs(55, 6, this << ": joined for id " << id
<< ": " << s
);
928 /* return a list of entries with the same id separated by ',' and ws */
930 HttpHeader::getList(http_hdr_type id
) const
933 HttpHeaderPos pos
= HttpHeaderInitPos
;
934 debugs(55, 9, this << "joining for id " << id
);
935 /* only fields from ListHeaders array can be "listed" */
936 assert(CBIT_TEST(ListHeadersMask
, id
));
938 if (!CBIT_TEST(mask
, id
))
943 while ((e
= getEntry(&pos
))) {
945 strListAdd(&s
, e
->value
.termedBuf(), ',');
949 * note: we might get an empty (size==0) string if there was an "empty"
950 * header. This results in an empty length String, which may have a NULL
953 /* temporary warning: remove it? (Is it useful for diagnostics ?) */
955 debugs(55, 3, "empty list header: " << headerTable
[id
].name
<< "(" << id
<< ")");
957 debugs(55, 6, this << ": joined for id " << id
<< ": " << s
);
962 /* return a string or list of entries with the same id separated by ',' and ws */
964 HttpHeader::getStrOrList(http_hdr_type id
) const
968 if (CBIT_TEST(ListHeadersMask
, id
))
971 if ((e
= findEntry(id
)))
978 * Returns the value of the specified header and/or an undefined String.
981 HttpHeader::getByName(const char *name
) const
984 // ignore presence: return undefined string if an empty header is present
985 (void)getByNameIfPresent(name
, result
);
990 HttpHeader::getByNameIfPresent(const char *name
, String
&result
) const
993 HttpHeaderPos pos
= HttpHeaderInitPos
;
998 /* First try the quick path */
999 id
= httpHeaderIdByNameDef(SBuf(name
));
1004 result
= getStrOrList(id
);
1008 /* Sorry, an unknown header name. Do linear search */
1010 while ((e
= getEntry(&pos
))) {
1011 if (e
->id
== HDR_OTHER
&& e
->name
.caseCmp(name
) == 0) {
1013 strListAdd(&result
, e
->value
.termedBuf(), ',');
1021 * Returns a the value of the specified list member, if any.
1024 HttpHeader::getByNameListMember(const char *name
, const char *member
, const char separator
) const
1027 const char *pos
= NULL
;
1030 int mlen
= strlen(member
);
1034 header
= getByName(name
);
1038 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1039 if (strncmp(item
, member
, mlen
) == 0 && item
[mlen
] == '=') {
1040 result
.append(item
+ mlen
+ 1, ilen
- mlen
- 1);
1049 * returns a the value of the specified list member, if any.
1052 HttpHeader::getListMember(http_hdr_type id
, const char *member
, const char separator
) const
1055 const char *pos
= NULL
;
1058 int mlen
= strlen(member
);
1062 header
= getStrOrList(id
);
1065 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1066 if (strncmp(item
, member
, mlen
) == 0 && item
[mlen
] == '=') {
1067 result
.append(item
+ mlen
+ 1, ilen
- mlen
- 1);
1076 /* test if a field is present */
1078 HttpHeader::has(http_hdr_type id
) const
1081 assert(id
!= HDR_OTHER
);
1082 debugs(55, 9, this << " lookup for " << id
);
1083 return CBIT_TEST(mask
, id
);
1087 HttpHeader::putInt(http_hdr_type id
, int number
)
1090 assert(headerTable
[id
].type
== ftInt
); /* must be of an appropriate type */
1091 assert(number
>= 0);
1092 addEntry(new HttpHeaderEntry(id
, NULL
, xitoa(number
)));
1096 HttpHeader::putInt64(http_hdr_type id
, int64_t number
)
1099 assert(headerTable
[id
].type
== ftInt64
); /* must be of an appropriate type */
1100 assert(number
>= 0);
1101 addEntry(new HttpHeaderEntry(id
, NULL
, xint64toa(number
)));
1105 HttpHeader::putTime(http_hdr_type id
, time_t htime
)
1108 assert(headerTable
[id
].type
== ftDate_1123
); /* must be of an appropriate type */
1110 addEntry(new HttpHeaderEntry(id
, NULL
, mkrfc1123(htime
)));
1114 HttpHeader::insertTime(http_hdr_type id
, time_t htime
)
1117 assert(headerTable
[id
].type
== ftDate_1123
); /* must be of an appropriate type */
1119 insertEntry(new HttpHeaderEntry(id
, NULL
, mkrfc1123(htime
)));
1123 HttpHeader::putStr(http_hdr_type id
, const char *str
)
1126 assert(headerTable
[id
].type
== ftStr
); /* must be of an appropriate type */
1128 addEntry(new HttpHeaderEntry(id
, NULL
, str
));
1132 HttpHeader::putAuth(const char *auth_scheme
, const char *realm
)
1134 assert(auth_scheme
&& realm
);
1135 httpHeaderPutStrf(this, HDR_WWW_AUTHENTICATE
, "%s realm=\"%s\"", auth_scheme
, realm
);
1139 HttpHeader::putCc(const HttpHdrCc
* cc
)
1142 /* remove old directives if any */
1143 delById(HDR_CACHE_CONTROL
);
1149 addEntry(new HttpHeaderEntry(HDR_CACHE_CONTROL
, NULL
, mb
.buf
));
1155 HttpHeader::putContRange(const HttpHdrContRange
* cr
)
1158 /* remove old directives if any */
1159 delById(HDR_CONTENT_RANGE
);
1163 httpHdrContRangePackInto(cr
, &mb
);
1165 addEntry(new HttpHeaderEntry(HDR_CONTENT_RANGE
, NULL
, mb
.buf
));
1171 HttpHeader::putRange(const HttpHdrRange
* range
)
1174 /* remove old directives if any */
1179 range
->packInto(&mb
);
1181 addEntry(new HttpHeaderEntry(HDR_RANGE
, NULL
, mb
.buf
));
1187 HttpHeader::putSc(HttpHdrSc
*sc
)
1190 /* remove old directives if any */
1191 delById(HDR_SURROGATE_CONTROL
);
1197 addEntry(new HttpHeaderEntry(HDR_SURROGATE_CONTROL
, NULL
, mb
.buf
));
1203 HttpHeader::putWarning(const int code
, const char *const text
)
1206 snprintf(buf
, sizeof(buf
), "%i %s \"%s\"", code
, visible_appname_string
, text
);
1207 putStr(HDR_WARNING
, buf
);
1210 /* add extension header (these fields are not parsed/analyzed/joined, etc.) */
1212 HttpHeader::putExt(const char *name
, const char *value
)
1214 assert(name
&& value
);
1215 debugs(55, 8, this << " adds ext entry " << name
<< " : " << value
);
1216 addEntry(new HttpHeaderEntry(HDR_OTHER
, name
, value
));
1220 HttpHeader::getInt(http_hdr_type id
) const
1223 assert(headerTable
[id
].type
== ftInt
); /* must be of an appropriate type */
1226 if ((e
= findEntry(id
)))
1233 HttpHeader::getInt64(http_hdr_type id
) const
1236 assert(headerTable
[id
].type
== ftInt64
); /* must be of an appropriate type */
1239 if ((e
= findEntry(id
)))
1240 return e
->getInt64();
1246 HttpHeader::getTime(http_hdr_type id
) const
1251 assert(headerTable
[id
].type
== ftDate_1123
); /* must be of an appropriate type */
1253 if ((e
= findEntry(id
))) {
1254 value
= parse_rfc1123(e
->value
.termedBuf());
1255 httpHeaderNoteParsedEntry(e
->id
, e
->value
, value
< 0);
1261 /* sync with httpHeaderGetLastStr */
1263 HttpHeader::getStr(http_hdr_type id
) const
1267 assert(headerTable
[id
].type
== ftStr
); /* must be of an appropriate type */
1269 if ((e
= findEntry(id
))) {
1270 httpHeaderNoteParsedEntry(e
->id
, e
->value
, 0); /* no errors are possible */
1271 return e
->value
.termedBuf();
1279 HttpHeader::getLastStr(http_hdr_type id
) const
1283 assert(headerTable
[id
].type
== ftStr
); /* must be of an appropriate type */
1285 if ((e
= findLastEntry(id
))) {
1286 httpHeaderNoteParsedEntry(e
->id
, e
->value
, 0); /* no errors are possible */
1287 return e
->value
.termedBuf();
1294 HttpHeader::getCc() const
1296 if (!CBIT_TEST(mask
, HDR_CACHE_CONTROL
))
1298 PROF_start(HttpHeader_getCc
);
1301 getList(HDR_CACHE_CONTROL
, &s
);
1303 HttpHdrCc
*cc
=new HttpHdrCc();
1305 if (!cc
->parse(s
)) {
1310 ++ HttpHeaderStats
[owner
].ccParsedCount
;
1313 httpHdrCcUpdateStats(cc
, &HttpHeaderStats
[owner
].ccTypeDistr
);
1315 httpHeaderNoteParsedEntry(HDR_CACHE_CONTROL
, s
, !cc
);
1317 PROF_stop(HttpHeader_getCc
);
1323 HttpHeader::getRange() const
1325 HttpHdrRange
*r
= NULL
;
1327 /* some clients will send "Request-Range" _and_ *matching* "Range"
1328 * who knows, some clients might send Request-Range only;
1329 * this "if" should work correctly in both cases;
1330 * hopefully no clients send mismatched headers! */
1332 if ((e
= findEntry(HDR_RANGE
)) ||
1333 (e
= findEntry(HDR_REQUEST_RANGE
))) {
1334 r
= HttpHdrRange::ParseCreate(&e
->value
);
1335 httpHeaderNoteParsedEntry(e
->id
, e
->value
, !r
);
1342 HttpHeader::getSc() const
1344 if (!CBIT_TEST(mask
, HDR_SURROGATE_CONTROL
))
1349 (void) getList(HDR_SURROGATE_CONTROL
, &s
);
1351 HttpHdrSc
*sc
= httpHdrScParseCreate(s
);
1353 ++ HttpHeaderStats
[owner
].ccParsedCount
;
1356 sc
->updateStats(&HttpHeaderStats
[owner
].scTypeDistr
);
1358 httpHeaderNoteParsedEntry(HDR_SURROGATE_CONTROL
, s
, !sc
);
1364 HttpHeader::getContRange() const
1366 HttpHdrContRange
*cr
= NULL
;
1369 if ((e
= findEntry(HDR_CONTENT_RANGE
))) {
1370 cr
= httpHdrContRangeParseCreate(e
->value
.termedBuf());
1371 httpHeaderNoteParsedEntry(e
->id
, e
->value
, !cr
);
1378 HttpHeader::getAuth(http_hdr_type id
, const char *auth_scheme
) const
1382 assert(auth_scheme
);
1385 if (!field
) /* no authorization field */
1388 l
= strlen(auth_scheme
);
1390 if (!l
|| strncasecmp(field
, auth_scheme
, l
)) /* wrong scheme */
1395 if (!xisspace(*field
)) /* wrong scheme */
1398 /* skip white space */
1399 for (; field
&& xisspace(*field
); ++field
);
1401 if (!*field
) /* no authorization cookie */
1404 static char decodedAuthToken
[8192];
1405 struct base64_decode_ctx ctx
;
1406 base64_decode_init(&ctx
);
1407 size_t decodedLen
= 0;
1408 if (!base64_decode_update(&ctx
, &decodedLen
, reinterpret_cast<uint8_t*>(decodedAuthToken
), strlen(field
), reinterpret_cast<const uint8_t*>(field
)) ||
1409 !base64_decode_final(&ctx
)) {
1412 decodedAuthToken
[decodedLen
] = '\0';
1413 return decodedAuthToken
;
1417 HttpHeader::getETag(http_hdr_type id
) const
1419 ETag etag
= {NULL
, -1};
1421 assert(headerTable
[id
].type
== ftETag
); /* must be of an appropriate type */
1423 if ((e
= findEntry(id
)))
1424 etagParseInit(&etag
, e
->value
.termedBuf());
1430 HttpHeader::getTimeOrTag(http_hdr_type id
) const
1434 assert(headerTable
[id
].type
== ftDate_1123_or_ETag
); /* must be of an appropriate type */
1435 memset(&tot
, 0, sizeof(tot
));
1437 if ((e
= findEntry(id
))) {
1438 const char *str
= e
->value
.termedBuf();
1439 /* try as an ETag */
1441 if (etagParseInit(&tot
.tag
, str
)) {
1442 tot
.valid
= tot
.tag
.str
!= NULL
;
1445 /* or maybe it is time? */
1446 tot
.time
= parse_rfc1123(str
);
1447 tot
.valid
= tot
.time
>= 0;
1452 assert(tot
.time
< 0 || !tot
.tag
.str
); /* paranoid */
1460 HttpHeaderEntry::HttpHeaderEntry(http_hdr_type anId
, const char *aName
, const char *aValue
)
1465 if (id
!= HDR_OTHER
)
1466 name
= headerTable
[id
].name
;
1472 ++ headerStatsTable
[id
].aliveCount
;
1474 debugs(55, 9, "created HttpHeaderEntry " << this << ": '" << name
<< " : " << value
);
1477 HttpHeaderEntry::~HttpHeaderEntry()
1480 debugs(55, 9, "destroying entry " << this << ": '" << name
<< ": " << value
<< "'");
1482 assert(headerStatsTable
[id
].aliveCount
); // is this really needed?
1484 -- headerStatsTable
[id
].aliveCount
;
1489 /* parses and inits header entry, returns true/false */
1491 HttpHeaderEntry::parse(const char *field_start
, const char *field_end
)
1493 /* note: name_start == field_start */
1494 const char *name_end
= (const char *)memchr(field_start
, ':', field_end
- field_start
);
1495 int name_len
= name_end
? name_end
- field_start
:0;
1496 const char *value_start
= field_start
+ name_len
+ 1; /* skip ':' */
1497 /* note: value_end == field_end */
1499 ++ HeaderEntryParsedCount
;
1501 /* do we have a valid field name within this field? */
1503 if (!name_len
|| name_end
> field_end
)
1506 if (name_len
> 65534) {
1507 /* String must be LESS THAN 64K and it adds a terminating NULL */
1508 debugs(55, DBG_IMPORTANT
, "WARNING: ignoring header name of " << name_len
<< " bytes");
1512 if (Config
.onoff
.relaxed_header_parser
&& xisspace(field_start
[name_len
- 1])) {
1513 debugs(55, Config
.onoff
.relaxed_header_parser
<= 0 ? 1 : 2,
1514 "NOTICE: Whitespace after header name in '" << getStringPrefix(field_start
, field_end
-field_start
) << "'");
1516 while (name_len
> 0 && xisspace(field_start
[name_len
- 1]))
1523 /* now we know we can parse it */
1525 debugs(55, 9, "parsing HttpHeaderEntry: near '" << getStringPrefix(field_start
, field_end
-field_start
) << "'");
1527 /* is it a "known" field? */
1528 http_hdr_type id
= headerLookupTable
.lookup(SBuf(field_start
,name_len
));
1529 debugs(55, 9, "got hdr id hdr: " << id
);
1540 /* set field name */
1541 if (id
== HDR_OTHER
)
1542 name
.limitInit(field_start
, name_len
);
1544 name
= headerTable
[id
].name
;
1546 /* trim field value */
1547 while (value_start
< field_end
&& xisspace(*value_start
))
1550 while (value_start
< field_end
&& xisspace(field_end
[-1]))
1553 if (field_end
- value_start
> 65534) {
1554 /* String must be LESS THAN 64K and it adds a terminating NULL */
1555 debugs(55, DBG_IMPORTANT
, "WARNING: ignoring '" << name
<< "' header of " << (field_end
- value_start
) << " bytes");
1557 if (id
== HDR_OTHER
)
1563 /* set field value */
1564 value
.limitInit(value_start
, field_end
- value_start
);
1566 ++ headerStatsTable
[id
].seenCount
;
1568 debugs(55, 9, "parsed HttpHeaderEntry: '" << name
<< ": " << value
<< "'");
1570 return new HttpHeaderEntry(id
, name
.termedBuf(), value
.termedBuf());
1574 HttpHeaderEntry::clone() const
1576 return new HttpHeaderEntry(id
, name
.termedBuf(), value
.termedBuf());
1580 HttpHeaderEntry::packInto(Packable
* p
) const
1583 p
->append(name
.rawBuf(), name
.size());
1585 p
->append(value
.rawBuf(), value
.size());
1586 p
->append("\r\n", 2);
1590 HttpHeaderEntry::getInt() const
1594 int ok
= httpHeaderParseInt(value
.termedBuf(), &val
);
1595 httpHeaderNoteParsedEntry(id
, value
, !ok
);
1596 /* XXX: Should we check ok - ie
1597 * return ok ? -1 : value;
1603 HttpHeaderEntry::getInt64() const
1607 int ok
= httpHeaderParseOffset(value
.termedBuf(), &val
);
1608 httpHeaderNoteParsedEntry(id
, value
, !ok
);
1609 /* XXX: Should we check ok - ie
1610 * return ok ? -1 : value;
1616 httpHeaderNoteParsedEntry(http_hdr_type id
, String
const &context
, int error
)
1618 ++ headerStatsTable
[id
].parsCount
;
1621 ++ headerStatsTable
[id
].errCount
;
1622 debugs(55, 2, "cannot parse hdr field: '" << headerTable
[id
].name
<< ": " << context
<< "'");
1630 /* tmp variable used to pass stat info to dumpers */
1631 extern const HttpHeaderStat
*dump_stat
; /* argh! */
1632 const HttpHeaderStat
*dump_stat
= NULL
;
1635 httpHeaderFieldStatDumper(StoreEntry
* sentry
, int, double val
, double, int count
)
1637 const int id
= (int) val
;
1638 const int valid_id
= id
>= 0 && id
< HDR_ENUM_END
;
1639 const char *name
= valid_id
? headerTable
[id
].name
: "INVALID";
1640 int visible
= count
> 0;
1641 /* for entries with zero count, list only those that belong to current type of message */
1643 if (!visible
&& valid_id
&& dump_stat
->owner_mask
)
1644 visible
= CBIT_TEST(*dump_stat
->owner_mask
, id
);
1647 storeAppendPrintf(sentry
, "%2d\t %-20s\t %5d\t %6.2f\n",
1648 id
, name
, count
, xdiv(count
, dump_stat
->busyDestroyedCount
));
1652 httpHeaderFldsPerHdrDumper(StoreEntry
* sentry
, int idx
, double val
, double, int count
)
1655 storeAppendPrintf(sentry
, "%2d\t %5d\t %5d\t %6.2f\n",
1656 idx
, (int) val
, count
,
1657 xpercent(count
, dump_stat
->destroyedCount
));
1661 httpHeaderStatDump(const HttpHeaderStat
* hs
, StoreEntry
* e
)
1666 storeAppendPrintf(e
, "\nHeader Stats: %s\n", hs
->label
);
1667 storeAppendPrintf(e
, "\nField type distribution\n");
1668 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1669 "id", "name", "count", "#/header");
1670 hs
->fieldTypeDistr
.dump(e
, httpHeaderFieldStatDumper
);
1671 storeAppendPrintf(e
, "\nCache-control directives distribution\n");
1672 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1673 "id", "name", "count", "#/cc_field");
1674 hs
->ccTypeDistr
.dump(e
, httpHdrCcStatDumper
);
1675 storeAppendPrintf(e
, "\nSurrogate-control directives distribution\n");
1676 storeAppendPrintf(e
, "%2s\t %-20s\t %5s\t %6s\n",
1677 "id", "name", "count", "#/sc_field");
1678 hs
->scTypeDistr
.dump(e
, httpHdrScStatDumper
);
1679 storeAppendPrintf(e
, "\nNumber of fields per header distribution\n");
1680 storeAppendPrintf(e
, "%2s\t %-5s\t %5s\t %6s\n",
1681 "id", "#flds", "count", "%total");
1682 hs
->hdrUCountDistr
.dump(e
, httpHeaderFldsPerHdrDumper
);
1683 storeAppendPrintf(e
, "\n");
1688 httpHeaderStoreReport(StoreEntry
* e
)
1691 // http_hdr_type ht;
1694 HttpHeaderStats
[0].parsedCount
=
1695 HttpHeaderStats
[hoRequest
].parsedCount
+ HttpHeaderStats
[hoReply
].parsedCount
;
1696 HttpHeaderStats
[0].ccParsedCount
=
1697 HttpHeaderStats
[hoRequest
].ccParsedCount
+ HttpHeaderStats
[hoReply
].ccParsedCount
;
1698 HttpHeaderStats
[0].destroyedCount
=
1699 HttpHeaderStats
[hoRequest
].destroyedCount
+ HttpHeaderStats
[hoReply
].destroyedCount
;
1700 HttpHeaderStats
[0].busyDestroyedCount
=
1701 HttpHeaderStats
[hoRequest
].busyDestroyedCount
+ HttpHeaderStats
[hoReply
].busyDestroyedCount
;
1703 for (i
= 1; i
< HttpHeaderStatCount
; ++i
) {
1704 httpHeaderStatDump(HttpHeaderStats
+ i
, e
);
1707 /* field stats for all messages */
1708 storeAppendPrintf(e
, "\nHttp Fields Stats (replies and requests)\n");
1710 storeAppendPrintf(e
, "%2s\t %-25s\t %5s\t %6s\t %6s\n",
1711 "id", "name", "#alive", "%err", "%repeat");
1713 // scan heaaderTable and output
1714 for (int j
= 0; headerTable
[j
].name
!= nullptr; ++j
) {
1715 auto stats
= headerStatsTable
[j
];
1716 storeAppendPrintf(e
, "%2d\t %-25s\t %5d\t %6.3f\t %6.3f\n",
1717 headerTable
[j
].id
, headerTable
[j
].name
, stats
.aliveCount
,
1718 xpercent(stats
.errCount
, stats
.parsCount
),
1719 xpercent(stats
.repCount
, stats
.seenCount
));
1722 storeAppendPrintf(e
, "Headers Parsed: %d + %d = %d\n",
1723 HttpHeaderStats
[hoRequest
].parsedCount
,
1724 HttpHeaderStats
[hoReply
].parsedCount
,
1725 HttpHeaderStats
[0].parsedCount
);
1726 storeAppendPrintf(e
, "Hdr Fields Parsed: %d\n", HeaderEntryParsedCount
);
1729 // (ab)used by other modules.
1731 httpHeaderIdByName(const char *name
, size_t name_len
, const HttpHeaderFieldInfo
* info
, int end
)
1734 for (int i
= 0; i
< end
; ++i
) {
1735 if (name_len
!= info
[i
].name
.size())
1738 if (!strncasecmp(name
, info
[i
].name
.rawBuf(), name_len
))
1747 httpHeaderIdByNameDef(const SBuf
&name
)
1749 return headerLookupTable
.lookup(name
);
1753 httpHeaderIdByNameDef(const char *name
, int name_len
)
1755 return headerLookupTable
.lookup(SBuf(name
,name_len
));
1759 httpHeaderNameById(int id
)
1761 assert(id
>= 0 && id
< HDR_ENUM_END
);
1762 return headerTable
[id
].name
;
1766 HttpHeader::hasListMember(http_hdr_type id
, const char *member
, const char separator
) const
1769 const char *pos
= NULL
;
1772 int mlen
= strlen(member
);
1776 String
header (getStrOrList(id
));
1778 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1779 if (strncasecmp(item
, member
, mlen
) == 0
1780 && (item
[mlen
] == '=' || item
[mlen
] == separator
|| item
[mlen
] == ';' || item
[mlen
] == '\0')) {
1790 HttpHeader::hasByNameListMember(const char *name
, const char *member
, const char separator
) const
1793 const char *pos
= NULL
;
1796 int mlen
= strlen(member
);
1800 String
header (getByName(name
));
1802 while (strListGetItem(&header
, separator
, &item
, &ilen
, &pos
)) {
1803 if (strncasecmp(item
, member
, mlen
) == 0
1804 && (item
[mlen
] == '=' || item
[mlen
] == separator
|| item
[mlen
] == ';' || item
[mlen
] == '\0')) {
1814 HttpHeader::removeHopByHopEntries()
1816 removeConnectionHeaderEntries();
1818 const HttpHeaderEntry
*e
;
1819 HttpHeaderPos pos
= HttpHeaderInitPos
;
1820 int headers_deleted
= 0;
1821 while ((e
= getEntry(&pos
))) {
1823 if (CBIT_TEST(HopByHopHeadersMask
, id
)) {
1824 delAt(pos
, headers_deleted
);
1831 HttpHeader::removeConnectionHeaderEntries()
1833 if (has(HDR_CONNECTION
)) {
1834 /* anything that matches Connection list member will be deleted */
1835 String strConnection
;
1837 (void) getList(HDR_CONNECTION
, &strConnection
);
1838 const HttpHeaderEntry
*e
;
1839 HttpHeaderPos pos
= HttpHeaderInitPos
;
1841 * think: on-average-best nesting of the two loops (hdrEntry
1842 * and strListItem) @?@
1845 * maybe we should delete standard stuff ("keep-alive","close")
1846 * from strConnection first?
1849 int headers_deleted
= 0;
1850 while ((e
= getEntry(&pos
))) {
1851 if (strListIsMember(&strConnection
, e
->name
.termedBuf(), ','))
1852 delAt(pos
, headers_deleted
);
1854 if (headers_deleted
)