Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: net/http/http_response_headers.cc

Issue 8511063: Improve merging of header modifications in webRequest.OnHeadersReceived (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index ad8ca3e0681ec96c7fba119622cea9ad85c748ec..341762b1bab381c039a6f945527685a03d21c608 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -294,6 +294,42 @@ void HttpResponseHeaders::MergeWithHeaders(const std::string& raw_headers,
Parse(new_raw_headers);
}
+void HttpResponseHeaders::MergeWithHeaders(
+ const std::string& raw_headers,
+ const std::string& header_to_remove_name,
+ const std::string& header_to_remove_value) {
+ std::string header_to_remove_name_lowercase(header_to_remove_name);
+ StringToLowerASCII(&header_to_remove_name_lowercase);
+
+ std::string new_raw_headers(raw_headers);
+ for (size_t i = 0; i < parsed_.size(); ++i) {
+ DCHECK(!parsed_[i].is_continuation());
+
+ // Locate the start of the next header.
+ size_t k = i;
+ while (++k < parsed_.size() && parsed_[k].is_continuation()) {}
+ --k;
+
+ std::string name(parsed_[i].name_begin, parsed_[i].name_end);
+ StringToLowerASCII(&name);
+ std::string value(parsed_[i].value_begin, parsed_[i].value_end);
+ if (name != header_to_remove_name_lowercase ||
+ value != header_to_remove_value) {
+ // It's ok to preserve this header in the final result.
+ new_raw_headers.append(parsed_[i].name_begin, parsed_[k].value_end);
+ new_raw_headers.push_back('\0');
+ }
+
+ i = k;
+ }
+ new_raw_headers.push_back('\0');
+
+ // Make this object hold the new data.
+ raw_headers_.clear();
+ parsed_.clear();
+ Parse(new_raw_headers);
+}
+
void HttpResponseHeaders::RemoveHeader(const std::string& name) {
// Copy up to the null byte. This just copies the status line.
std::string new_raw_headers(raw_headers_.c_str());
@@ -306,6 +342,15 @@ void HttpResponseHeaders::RemoveHeader(const std::string& name) {
MergeWithHeaders(new_raw_headers, to_remove);
}
+void HttpResponseHeaders::RemoveHeader(const std::string& name,
+ const std::string& value) {
+ // Copy up to the null byte. This just copies the status line.
+ std::string new_raw_headers(raw_headers_.c_str());
+ new_raw_headers.push_back('\0');
+
+ MergeWithHeaders(new_raw_headers, name, value);
+}
+
void HttpResponseHeaders::AddHeader(const std::string& header) {
CheckDoesNotHaveEmbededNulls(header);
DCHECK_EQ('\0', raw_headers_[raw_headers_.size() - 2]);

Powered by Google App Engine
This is Rietveld 408576698