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

Unified Diff: net/http/http_response_headers.cc

Issue 10809011: Fix removal of headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit Created 8 years, 5 months 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
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 6fe8e2fd7ceba8b502a6fbdea1dd1446ec2958a0..90766ba9c8fc76a785ee84b4b88176f3ada7ede9 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -311,42 +311,6 @@ void HttpResponseHeaders::MergeWithHeaders(const std::string& raw_headers,
Parse(new_raw_headers);
}
-void HttpResponseHeaders::MergeWithHeadersWithValue(
- 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());
@@ -359,13 +323,39 @@ void HttpResponseHeaders::RemoveHeader(const std::string& name) {
MergeWithHeaders(new_raw_headers, to_remove);
}
-void HttpResponseHeaders::RemoveHeaderWithValue(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());
+void HttpResponseHeaders::RemoveHeaderLine(const std::string& name,
+ const std::string& value) {
+ std::string name_lowercase(name);
+ StringToLowerASCII(&name_lowercase);
+
+ std::string new_raw_headers(GetStatusLine());
+ new_raw_headers.push_back('\0');
+
+ new_raw_headers.reserve(raw_headers_.size());
+
+ void* iter = NULL;
+ std::string old_header_name;
+ std::string old_header_value;
+ while (EnumerateHeaderLines(&iter, &old_header_name, &old_header_value)) {
+ std::string old_header_name_lowercase(name);
+ StringToLowerASCII(&old_header_name_lowercase);
+
+ if (name_lowercase == old_header_name_lowercase &&
+ value == old_header_value)
+ continue;
+
+ new_raw_headers.append(old_header_name);
+ new_raw_headers.push_back(':');
+ new_raw_headers.push_back(' ');
+ new_raw_headers.append(old_header_value);
+ new_raw_headers.push_back('\0');
+ }
new_raw_headers.push_back('\0');
- MergeWithHeadersWithValue(new_raw_headers, name, value);
+ // Make this object hold the new data.
+ raw_headers_.clear();
+ parsed_.clear();
+ Parse(new_raw_headers);
}
void HttpResponseHeaders::AddHeader(const std::string& header) {
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698