Escape non-ASCII response headers.

Response headers that are not valid UTF-8 can't be stored in a
base::StringValue, which is always a UTF-8 string, so escape any non-ASCII
values to be safe. This prevents a DCHECK when dev tools' network request
inspector is open and we receive these headers.

BUG=299880

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

Cr-Commit-Position: refs/heads/master@{#288357}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288357 0039d316-1c4b-4281-b951-d872f2087c98
parent 9ca4a5da
...@@ -1355,9 +1355,12 @@ base::Value* HttpResponseHeaders::NetLogCallback( ...@@ -1355,9 +1355,12 @@ base::Value* HttpResponseHeaders::NetLogCallback(
std::string value; std::string value;
while (EnumerateHeaderLines(&iterator, &name, &value)) { while (EnumerateHeaderLines(&iterator, &name, &value)) {
std::string log_value = ElideHeaderValueForNetLog(log_level, name, value); std::string log_value = ElideHeaderValueForNetLog(log_level, name, value);
std::string escaped_name = EscapeNonASCII(name);
std::string escaped_value = EscapeNonASCII(log_value);
headers->Append( headers->Append(
new base::StringValue( new base::StringValue(
base::StringPrintf("%s: %s", name.c_str(), log_value.c_str()))); base::StringPrintf("%s: %s", escaped_name.c_str(),
escaped_value.c_str())));
} }
dict->Set("headers", headers); dict->Set("headers", headers);
return dict; return dict;
......
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