Commit 12b4a561 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Make webview code use two argument ResponseHeader manipulation calls

We want to get rid of the single argument AddHeader() method as the two
argument AddHeader() and SetHeader() methods are safer and more
flexible.

Change-Id: Id6a5288d453e0e7d8bbe59cc1938f5a14f79d3bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147674
Auto-Submit: Matt Menke <mmenke@chromium.org>
Commit-Queue: Richard Coles <torne@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758949}
parent a6a899b4
...@@ -32,8 +32,9 @@ namespace android_webview { ...@@ -32,8 +32,9 @@ namespace android_webview {
namespace { namespace {
const char kResponseHeaderViaShouldInterceptRequest[] = const char kResponseHeaderViaShouldInterceptRequestName[] = "Client-Via";
"Client-Via: shouldInterceptRequest"; const char kResponseHeaderViaShouldInterceptRequestValue[] =
"shouldInterceptRequest";
const char kHTTPOkText[] = "OK"; const char kHTTPOkText[] = "OK";
const char kHTTPNotFoundText[] = "Not Found"; const char kHTTPNotFoundText[] = "Not Found";
...@@ -237,12 +238,8 @@ void AndroidStreamReaderURLLoader::HeadersComplete( ...@@ -237,12 +238,8 @@ void AndroidStreamReaderURLLoader::HeadersComplete(
&head.charset); &head.charset);
if (expected_content_size_ != -1) { if (expected_content_size_ != -1) {
std::string content_length_header( head.headers->SetHeader(net::HttpRequestHeaders::kContentLength,
net::HttpRequestHeaders::kContentLength);
content_length_header.append(": ");
content_length_header.append(
base::NumberToString(expected_content_size_)); base::NumberToString(expected_content_size_));
head.headers->AddHeader(content_length_header);
head.content_length = expected_content_size_; head.content_length = expected_content_size_;
} }
...@@ -251,10 +248,7 @@ void AndroidStreamReaderURLLoader::HeadersComplete( ...@@ -251,10 +248,7 @@ void AndroidStreamReaderURLLoader::HeadersComplete(
env, resource_request_.url, env, resource_request_.url,
input_stream_reader_wrapper_->input_stream(), &mime_type) && input_stream_reader_wrapper_->input_stream(), &mime_type) &&
!mime_type.empty()) { !mime_type.empty()) {
std::string content_type_header(net::HttpRequestHeaders::kContentType); head.headers->SetHeader(net::HttpRequestHeaders::kContentType, mime_type);
content_type_header.append(": ");
content_type_header.append(mime_type);
head.headers->AddHeader(content_type_header);
head.mime_type = mime_type; head.mime_type = mime_type;
} }
} }
...@@ -264,7 +258,8 @@ void AndroidStreamReaderURLLoader::HeadersComplete( ...@@ -264,7 +258,8 @@ void AndroidStreamReaderURLLoader::HeadersComplete(
// Indicate that the response had been obtained via shouldInterceptRequest. // Indicate that the response had been obtained via shouldInterceptRequest.
// TODO(jam): why is this added for protocol handler (e.g. content scheme and // TODO(jam): why is this added for protocol handler (e.g. content scheme and
// file resources?). The old path does this as well. // file resources?). The old path does this as well.
head.headers->AddHeader(kResponseHeaderViaShouldInterceptRequest); head.headers->SetHeader(kResponseHeaderViaShouldInterceptRequestName,
kResponseHeaderViaShouldInterceptRequestValue);
SendBody(); SendBody();
} }
......
...@@ -136,10 +136,7 @@ class TestResponseDelegate ...@@ -136,10 +136,7 @@ class TestResponseDelegate
return; return;
} }
headers->ReplaceStatusLine(custom_status_); headers->ReplaceStatusLine(custom_status_);
std::string header_line(custom_header_name_); headers->AddHeader(custom_header_name_, custom_header_value_);
header_line.append(": ");
header_line.append(custom_header_value_);
headers->AddHeader(header_line);
} }
private: private:
......
...@@ -104,10 +104,7 @@ bool AwWebResourceResponse::GetResponseHeaders( ...@@ -104,10 +104,7 @@ bool AwWebResourceResponse::GetResponseHeaders(
&header_values); &header_values);
DCHECK_EQ(header_values.size(), header_names.size()); DCHECK_EQ(header_values.size(), header_names.size());
for (size_t i = 0; i < header_names.size(); ++i) { for (size_t i = 0; i < header_names.size(); ++i) {
std::string header_line(header_names[i]); headers->AddHeader(header_names[i], header_values[i]);
header_line.append(": ");
header_line.append(header_values[i]);
headers->AddHeader(header_line);
} }
return true; return true;
} }
......
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