Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ void HeaderToMetadataFilter::writeHeaderToMetadata(Http::HeaderMap& headers,
if (rule.remove()) {
headers.remove(header);
}
} else if (rule.has_on_header_missing()) {
}
if (header_entry == nullptr && rule.has_on_header_missing()) {
// Add metadata for the header missing case.
const auto& keyval = rule.on_header_missing();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,27 @@ TEST_F(HeaderToMetadataTest, NoEmptyValues) {
EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(headers, false));
}

/**
* Missing case is not executed when header is present.
*/
TEST_F(HeaderToMetadataTest, NoMissingWhenHeaderIsPresent) {
const std::string config = R"EOF(
request_rules:
- header: x-version
on_header_missing:
metadata_namespace: envoy.lb
key: version
value: some_value
type: STRING
)EOF";
initializeFilter(config);
Http::TestRequestHeaderMapImpl headers{{"x-version", ""}};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add value to the header (to avoid conflating with the internal handling of headers without a value).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR. <3


EXPECT_CALL(decoder_callbacks_, streamInfo()).WillRepeatedly(ReturnRef(req_info_));
EXPECT_CALL(req_info_, setDynamicMetadata(_, _)).Times(0);
EXPECT_EQ(Http::FilterHeadersStatus::Continue, filter_->decodeHeaders(headers, false));
}

} // namespace HeaderToMetadataFilter
} // namespace HttpFilters
} // namespace Extensions
Expand Down