Commit 4109859a authored by rob's avatar rob Committed by Commit bot

Use EnumerateHeaderLines to parse added headers in webRequest API

The responseHeaders that are passed to the webRequest.onHeadersReceived
event are generated by the GetResponseHeadersList method. This method
enumerates the headers using HttpResponseHeaders::EnumerateHeaderLines,
which skips over commas in header values.
But the return value of the webRequest.onHeadersReceived handler is
parsed by HttpResponseHeaders:EnumerateHeader, which stops at commas.
So, if the original response header contains a comma, and the extension
returns the response headers in unmodified form, it was still mistakenly
flagged as modified. This results in duplication of headers.

To fix this, the return value is now parsed using EnumerateHeaderLines.

BUG=526367
TEST=unit_tests --gtest_filter=ExtensionWebRequestHelpersTest.*

Review URL: https://codereview.chromium.org/1315643005

Cr-Commit-Position: refs/heads/master@{#347896}
parent 1a5ac407
......@@ -1287,6 +1287,7 @@ TEST(ExtensionWebRequestHelpersTest, TestCalculateOnHeadersReceivedDelta) {
"Key1: Value1\r\n"
"Key2: Value2, Bar\r\n"
"Key3: Value3\r\n"
"Key5: Value5, end5\r\n"
"\r\n";
scoped_refptr<net::HttpResponseHeaders> base_headers(
new net::HttpResponseHeaders(
......@@ -1298,6 +1299,7 @@ TEST(ExtensionWebRequestHelpersTest, TestCalculateOnHeadersReceivedDelta) {
new_headers.push_back(ResponseHeader("Key2", "Value1")); // Modified
// Key3 is deleted
new_headers.push_back(ResponseHeader("Key4", "Value4")); // Added
new_headers.push_back(ResponseHeader("Key5", "Value5, end5")); // Unchanged
GURL effective_new_url;
scoped_ptr<EventResponseDelta> delta(
......
......@@ -361,17 +361,21 @@ EventResponseDelta* CalculateOnHeadersReceivedDelta(
// Find added headers (header keys are treated case insensitively).
{
for (ResponseHeaders::const_iterator i = new_response_headers->begin();
i != new_response_headers->end(); ++i) {
void* iter = NULL;
for (const auto& i : *new_response_headers) {
std::string name_lowercase = base::ToLowerASCII(i.first);
void* iter = nullptr;
std::string name;
std::string value;
bool header_found = false;
while (old_response_headers->EnumerateHeader(&iter, i->first, &value) &&
!header_found) {
header_found = (value == i->second);
while (old_response_headers->EnumerateHeaderLines(&iter, &name, &value)) {
if (base::LowerCaseEqualsASCII(name, name_lowercase) &&
value == i.second) {
header_found = true;
break;
}
}
if (!header_found)
result->added_response_headers.push_back(*i);
result->added_response_headers.push_back(i);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment