Skip to content

Commit

Permalink
Avoid unnecessary conversions to LowerCaseString
Browse files Browse the repository at this point in the history
Also, rebase on master because well-known-names.h changed.

Signed-off-by: Raul Gutierrez Segales <[email protected]>
  • Loading branch information
Raul Gutierrez Segales committed Jun 14, 2018
1 parent 51813a0 commit 950cbb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ MetadataKeyValue Config::toKeyValue(
}

Rule Config::toRule(const envoy::config::filter::http::header_to_metadata::v2::Rule& entry) {
Rule rule;
Rule rule(entry.header());

rule.header = entry.header();
rule.onHeaderPresent = toKeyValue(entry.on_header_present());
rule.onHeaderMissing = toKeyValue(entry.on_header_missing());
rule.remove = entry.remove();
Expand Down Expand Up @@ -143,8 +142,7 @@ bool HeaderToMetadataFilter::addMetadata(StructMap& map, const std::string& meta
}

auto& keyval = namespaceIter->second;
Http::LowerCaseString metadata_key(key);
(*keyval.mutable_fields())[metadata_key.get()] = val;
(*keyval.mutable_fields())[key] = val;

return true;
}
Expand All @@ -159,9 +157,8 @@ void HeaderToMetadataFilter::writeHeaderToMetadata(Http::HeaderMap& headers,
StructMap structsByNamespace;

for (const auto& rule : rules) {
Http::LowerCaseString header(rule.header);
const Http::HeaderEntry* header_entry = headers.get(rule.header);

const Http::HeaderEntry* header_entry = headers.get(header);
if (header_entry != nullptr) {
const auto& value = rule.onHeaderPresent.value.empty()
? std::string(header_entry->value().getStringView())
Expand All @@ -172,7 +169,7 @@ void HeaderToMetadataFilter::writeHeaderToMetadata(Http::HeaderMap& headers,
rule.onHeaderPresent.type);

if (rule.remove) {
headers.remove(header);
headers.remove(rule.header);
}
} else {
// Should we add metadata if the header is missing?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ struct MetadataKeyValue {
};

struct Rule {
std::string header;
Rule(const std::string& hdr) : header(hdr) {}
Http::LowerCaseString header;
MetadataKeyValue onHeaderPresent;
MetadataKeyValue onHeaderMissing;
bool remove;
Expand Down

0 comments on commit 950cbb1

Please sign in to comment.