Skip to content

Commit

Permalink
-> remove_if, fix for inline removal
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Apr 24, 2018
1 parent 31e05c0 commit d9dd886
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
22 changes: 15 additions & 7 deletions source/common/http/header_map_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,22 @@ void HeaderMapImpl::remove(const LowerCaseString& key) {
}

void HeaderMapImpl::remove(const std::regex& regex) {
for (auto i = headers_.begin(); i != headers_.end();) {
absl::string_view key = i->key().getStringView();
if (std::regex_search(key.begin(), key.end(), regex)) {
i = headers_.erase(i);
} else {
++i;
headers_.remove_if([&](const HeaderEntryImpl& entry) {
absl::string_view key = entry.key().getStringView();
bool to_remove = std::regex_search(key.begin(), key.end(), regex);
if (to_remove) {
// If this header should be removed, make sure any references in the
// static lookup table are cleared as well.
StaticLookupEntry::EntryCb cb = ConstSingleton<StaticLookupTable>::get().find(key.data());
if (cb) {
StaticLookupResponse ref_lookup_response = cb(*this);
if (ref_lookup_response.entry_) {
*ref_lookup_response.entry_ = nullptr;
}
}
}
}
return to_remove;
});
}

HeaderMapImpl::HeaderEntryImpl& HeaderMapImpl::maybeCreateInline(HeaderEntryImpl** entry,
Expand Down
7 changes: 7 additions & 0 deletions test/common/http/header_map_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ TEST(HeaderMapImplTest, RemoveRegex) {
headers.remove(std::regex(".*"));
EXPECT_EQ(nullptr, headers.get(key2));
EXPECT_EQ(nullptr, headers.get(key4));

// Add inline and remove by regex
headers.insertContentLength().value(5);
EXPECT_STREQ("5", headers.ContentLength()->value().c_str());
EXPECT_EQ(1UL, headers.size());
headers.remove(std::regex("content"));
EXPECT_EQ(nullptr, headers.ContentLength());
}

TEST(HeaderMapImplTest, SetRemovesAllValues) {
Expand Down

0 comments on commit d9dd886

Please sign in to comment.