| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // The rules for header parsing were borrowed from Firefox: | 5 // The rules for header parsing were borrowed from Firefox: |
| 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp | 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo
nseHead.cpp |
| 7 // The rules for parsing content-types were also borrowed from Firefox: | 7 // The rules for parsing content-types were also borrowed from Firefox: |
| 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
| 9 | 9 |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // This copies the status line w/ terminator null. | 130 // This copies the status line w/ terminator null. |
| 131 // Note raw_headers_ has embedded nulls instead of \n, | 131 // Note raw_headers_ has embedded nulls instead of \n, |
| 132 // so this just copies the first header line. | 132 // so this just copies the first header line. |
| 133 blob.assign(raw_headers_.c_str(), strlen(raw_headers_.c_str()) + 1); | 133 blob.assign(raw_headers_.c_str(), strlen(raw_headers_.c_str()) + 1); |
| 134 | 134 |
| 135 for (size_t i = 0; i < parsed_.size(); ++i) { | 135 for (size_t i = 0; i < parsed_.size(); ++i) { |
| 136 DCHECK(!parsed_[i].is_continuation()); | 136 DCHECK(!parsed_[i].is_continuation()); |
| 137 | 137 |
| 138 // Locate the start of the next header. | 138 // Locate the start of the next header. |
| 139 size_t k = i; | 139 size_t k = i; |
| 140 while (++k < parsed_.size() && parsed_[k].is_continuation()); | 140 while (++k < parsed_.size() && parsed_[k].is_continuation()) {} |
| 141 --k; | 141 --k; |
| 142 | 142 |
| 143 std::string header_name(parsed_[i].name_begin, parsed_[i].name_end); | 143 std::string header_name(parsed_[i].name_begin, parsed_[i].name_end); |
| 144 StringToLowerASCII(&header_name); | 144 StringToLowerASCII(&header_name); |
| 145 | 145 |
| 146 if (filter_headers.find(header_name) == filter_headers.end()) { | 146 if (filter_headers.find(header_name) == filter_headers.end()) { |
| 147 // Make sure there is a null after the value. | 147 // Make sure there is a null after the value. |
| 148 blob.append(parsed_[i].name_begin, parsed_[k].value_end); | 148 blob.append(parsed_[i].name_begin, parsed_[k].value_end); |
| 149 blob.push_back('\0'); | 149 blob.push_back('\0'); |
| 150 } | 150 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 170 // order should not matter. | 170 // order should not matter. |
| 171 | 171 |
| 172 // Figure out which headers we want to take from new_headers: | 172 // Figure out which headers we want to take from new_headers: |
| 173 for (size_t i = 0; i < new_headers.parsed_.size(); ++i) { | 173 for (size_t i = 0; i < new_headers.parsed_.size(); ++i) { |
| 174 const HeaderList& new_parsed = new_headers.parsed_; | 174 const HeaderList& new_parsed = new_headers.parsed_; |
| 175 | 175 |
| 176 DCHECK(!new_parsed[i].is_continuation()); | 176 DCHECK(!new_parsed[i].is_continuation()); |
| 177 | 177 |
| 178 // Locate the start of the next header. | 178 // Locate the start of the next header. |
| 179 size_t k = i; | 179 size_t k = i; |
| 180 while (++k < new_parsed.size() && new_parsed[k].is_continuation()); | 180 while (++k < new_parsed.size() && new_parsed[k].is_continuation()) {} |
| 181 --k; | 181 --k; |
| 182 | 182 |
| 183 const std::string::const_iterator& name_begin = new_parsed[i].name_begin; | 183 const std::string::const_iterator& name_begin = new_parsed[i].name_begin; |
| 184 const std::string::const_iterator& name_end = new_parsed[i].name_end; | 184 const std::string::const_iterator& name_end = new_parsed[i].name_end; |
| 185 if (ShouldUpdateHeader(name_begin, name_end)) { | 185 if (ShouldUpdateHeader(name_begin, name_end)) { |
| 186 std::string name(name_begin, name_end); | 186 std::string name(name_begin, name_end); |
| 187 StringToLowerASCII(&name); | 187 StringToLowerASCII(&name); |
| 188 updated_headers.insert(name); | 188 updated_headers.insert(name); |
| 189 | 189 |
| 190 // Preserve this header line in the merged result, making sure there is | 190 // Preserve this header line in the merged result, making sure there is |
| (...skipping 10 matching lines...) Expand all Loading... |
| 201 } | 201 } |
| 202 | 202 |
| 203 void HttpResponseHeaders::MergeWithHeaders(const std::string& raw_headers, | 203 void HttpResponseHeaders::MergeWithHeaders(const std::string& raw_headers, |
| 204 const HeaderSet& headers_to_remove) { | 204 const HeaderSet& headers_to_remove) { |
| 205 std::string new_raw_headers(raw_headers); | 205 std::string new_raw_headers(raw_headers); |
| 206 for (size_t i = 0; i < parsed_.size(); ++i) { | 206 for (size_t i = 0; i < parsed_.size(); ++i) { |
| 207 DCHECK(!parsed_[i].is_continuation()); | 207 DCHECK(!parsed_[i].is_continuation()); |
| 208 | 208 |
| 209 // Locate the start of the next header. | 209 // Locate the start of the next header. |
| 210 size_t k = i; | 210 size_t k = i; |
| 211 while (++k < parsed_.size() && parsed_[k].is_continuation()); | 211 while (++k < parsed_.size() && parsed_[k].is_continuation()) {} |
| 212 --k; | 212 --k; |
| 213 | 213 |
| 214 std::string name(parsed_[i].name_begin, parsed_[i].name_end); | 214 std::string name(parsed_[i].name_begin, parsed_[i].name_end); |
| 215 StringToLowerASCII(&name); | 215 StringToLowerASCII(&name); |
| 216 if (headers_to_remove.find(name) == headers_to_remove.end()) { | 216 if (headers_to_remove.find(name) == headers_to_remove.end()) { |
| 217 // It's ok to preserve this header in the final result. | 217 // It's ok to preserve this header in the final result. |
| 218 new_raw_headers.append(parsed_[i].name_begin, parsed_[k].value_end); | 218 new_raw_headers.append(parsed_[i].name_begin, parsed_[k].value_end); |
| 219 new_raw_headers.push_back('\0'); | 219 new_raw_headers.push_back('\0'); |
| 220 } | 220 } |
| 221 | 221 |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 // We have all the values; let's verify that they make sense for a 206 | 1160 // We have all the values; let's verify that they make sense for a 206 |
| 1161 // response. | 1161 // response. |
| 1162 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1162 if (*first_byte_position < 0 || *last_byte_position < 0 || |
| 1163 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1163 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
| 1164 return false; | 1164 return false; |
| 1165 | 1165 |
| 1166 return true; | 1166 return true; |
| 1167 } | 1167 } |
| 1168 | 1168 |
| 1169 } // namespace net | 1169 } // namespace net |
| OLD | NEW |