Fix duplicate entries in CefRequest header map (issue #1840)

This commit is contained in:
Marshall Greenblatt 2016-03-01 18:59:53 -05:00
parent 1b7c5303ce
commit e1aa8cc109
3 changed files with 30 additions and 7 deletions

View File

@ -147,25 +147,28 @@ blink::WebString FilePathStringToWebString(
// Read |headers| into |map|. // Read |headers| into |map|.
void GetHeaderMap(const net::HttpRequestHeaders& headers, void GetHeaderMap(const net::HttpRequestHeaders& headers,
CefRequest::HeaderMap& map) { CefRequest::HeaderMap& map) {
map.clear();
if (headers.IsEmpty()) if (headers.IsEmpty())
return; return;
net::HttpRequestHeaders::Iterator it(headers); net::HttpRequestHeaders::Iterator it(headers);
do { while (it.GetNext()) {
const std::string& name = it.name(); const std::string& name = it.name();
// Do not include Referer in the header map. // Do not include Referer in the header map.
if (!base::LowerCaseEqualsASCII(name, kReferrerLowerCase)) if (!base::LowerCaseEqualsASCII(name, kReferrerLowerCase))
map.insert(std::make_pair(name, it.value())); map.insert(std::make_pair(name, it.value()));
} while (it.GetNext()); };
} }
// Read |request| into |map|. If a Referer value is specified populate // Read |request| into |map|. If a Referer value is specified populate
// |referrer|. // |referrer|.
void GetHeaderMap(const blink::WebURLRequest& request, void GetHeaderMap(const blink::WebURLRequest& request,
CefRequest::HeaderMap& map, CefRequest::HeaderMap& map,
CefString& referrer) { CefString& referrer) {
map.clear();
class HeaderVisitor : public blink::WebHTTPHeaderVisitor { class HeaderVisitor : public blink::WebHTTPHeaderVisitor {
public: public:
HeaderVisitor(CefRequest::HeaderMap* map, CefString* referrer) HeaderVisitor(CefRequest::HeaderMap* map, CefString* referrer)
@ -195,6 +198,8 @@ void GetHeaderMap(const blink::WebURLRequest& request,
// Read |source| into |map|. // Read |source| into |map|.
void GetHeaderMap(const CefRequest::HeaderMap& source, void GetHeaderMap(const CefRequest::HeaderMap& source,
CefRequest::HeaderMap& map) { CefRequest::HeaderMap& map) {
map.clear();
CefRequest::HeaderMap::const_iterator it = source.begin(); CefRequest::HeaderMap::const_iterator it = source.begin();
for (; it != source.end(); ++it) { for (; it != source.end(); ++it) {
const CefString& name = it->first; const CefString& name = it->first;

View File

@ -8,11 +8,15 @@
#include "tests/unittests/test_util.h" #include "tests/unittests/test_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
void TestMapEqual(CefRequest::HeaderMap& map1, void TestMapEqual(const CefRequest::HeaderMap& map1,
CefRequest::HeaderMap& map2, const CefRequest::HeaderMap& map2,
bool allowExtras) { bool allowExtras) {
if (!allowExtras) if (!allowExtras)
EXPECT_EQ(map1.size(), map2.size()); EXPECT_EQ(map1.size(), map2.size());
TestMapNoDuplicates(map1);
TestMapNoDuplicates(map2);
CefRequest::HeaderMap::const_iterator it1, it2; CefRequest::HeaderMap::const_iterator it1, it2;
for (it1 = map1.begin(); it1 != map1.end(); ++it1) { for (it1 = map1.begin(); it1 != map1.end(); ++it1) {
@ -25,6 +29,17 @@ void TestMapEqual(CefRequest::HeaderMap& map1,
} }
} }
void TestMapNoDuplicates(const CefRequest::HeaderMap& map) {
CefRequest::HeaderMap::const_iterator it1 = map.begin();
for (; it1 != map.end(); ++it1) {
CefRequest::HeaderMap::const_iterator it2 = it1;
for (++it2; it2 != map.end(); ++it2) {
EXPECT_FALSE(it1->first == it2->first && it1->second == it2->second) <<
"Duplicate entry for " << it1->first << ": " << it1->second;
}
}
}
void TestPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1, void TestPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1,
CefRefPtr<CefPostDataElement> elem2) { CefRefPtr<CefPostDataElement> elem2) {
EXPECT_TRUE(elem1.get()); EXPECT_TRUE(elem1.get());

View File

@ -14,10 +14,13 @@
// Test that CefRequest::HeaderMap objects are equal // Test that CefRequest::HeaderMap objects are equal
// If |allowExtras| is true then additional header fields will be allowed in // If |allowExtras| is true then additional header fields will be allowed in
// |map2|. // |map2|.
void TestMapEqual(CefRequest::HeaderMap& map1, void TestMapEqual(const CefRequest::HeaderMap& map1,
CefRequest::HeaderMap& map2, const CefRequest::HeaderMap& map2,
bool allowExtras); bool allowExtras);
// Test that the CefRequest::HeaderMap object contains no duplicate entries.
void TestMapNoDuplicates(const CefRequest::HeaderMap& map);
// Test that CefPostDataElement objects are equal // Test that CefPostDataElement objects are equal
void TestPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1, void TestPostDataElementEqual(CefRefPtr<CefPostDataElement> elem1,
CefRefPtr<CefPostDataElement> elem2); CefRefPtr<CefPostDataElement> elem2);