2 * Copyright (C) 1996-2021 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.
10 #include "RegisteredHeaders.h"
17 /* glue to code generated by gperf */
18 #include "http/RegisteredHeadersHash.cci"
20 HeaderTableRecord::HeaderTableRecord() :
21 name(""), id(HdrType::BAD_HDR
), type(HdrFieldType::ftInvalid
),
22 list(false), request(false), reply(false), hopbyhop(false), denied304(false)
25 HeaderTableRecord::HeaderTableRecord(const char *n
) :
26 name(n
), id(HdrType::BAD_HDR
), type(HdrFieldType::ftInvalid
),
27 list(false), request(false), reply(false), hopbyhop(false), denied304(false)
30 HeaderTableRecord::HeaderTableRecord(const char *n
, HdrType theId
, HdrFieldType theType
, int theKind
) :
31 name(n
), id(theId
), type(theType
),
32 list(theKind
& HdrKind::ListHeader
), request(theKind
& HdrKind::RequestHeader
),
33 reply(theKind
& HdrKind::ReplyHeader
), hopbyhop(theKind
& HdrKind::HopByHopHeader
),
34 denied304(theKind
& HdrKind::Denied304Header
)
37 const HeaderTableRecord
&
38 HeaderLookupTable_t::lookup (const char *buf
, const std::size_t len
) const {
39 const HeaderTableRecord
*r
= HttpHeaderHashTable::lookup(buf
, len
);
40 if (!r
|| r
->id
== Http::HdrType::OTHER
)
44 const HeaderTableRecord
HeaderLookupTable_t::BadHdr
{"*INVALID*:", Http::HdrType::BAD_HDR
, Http::HdrFieldType::ftInvalid
, HdrKind::None
};
46 HeaderLookupTable_t::HeaderLookupTable_t()
52 HeaderLookupTable_t::initCache()
54 idCache
.resize(TOTAL_KEYWORDS
);
55 for (int j
= MIN_HASH_VALUE
; j
<= MAX_HASH_VALUE
; ++j
) { //MAX_HASH_VALUE is exported by gperf
56 if (HttpHeaderDefinitionsTable
[j
].name
[0] != '\0') { //some slots are empty
57 idCache
[static_cast<int>(HttpHeaderDefinitionsTable
[j
].id
)] =
58 & HttpHeaderDefinitionsTable
[j
];
61 //check after the fact. The cache array must be full
62 for (auto e
: idCache
) {
66 const HeaderLookupTable_t HeaderLookupTable
;
68 }; /* namespace Http */
71 operator<< (std::ostream
&s
, Http::HdrType id
)
73 if (Http::any_HdrType_enum_value(id
))
74 s
<< Http::HeaderLookupTable
.lookup(id
).name
<< '[' << static_cast<int>(id
) << ']';
76 s
<< "Invalid-Header[" << static_cast<int>(id
) << ']';