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

Side by Side Diff: net/http/http_response_headers.cc

Issue 1800003: Auto-format style pass over files. (Closed)
Patch Set: Remove trailing whitespace. Created 10 years, 7 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 unified diff | Download patch
OLDNEW
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 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 267
268 void HttpResponseHeaders::Parse(const std::string& raw_input) { 268 void HttpResponseHeaders::Parse(const std::string& raw_input) {
269 raw_headers_.reserve(raw_input.size()); 269 raw_headers_.reserve(raw_input.size());
270 270
271 // ParseStatusLine adds a normalized status line to raw_headers_ 271 // ParseStatusLine adds a normalized status line to raw_headers_
272 std::string::const_iterator line_begin = raw_input.begin(); 272 std::string::const_iterator line_begin = raw_input.begin();
273 std::string::const_iterator line_end = 273 std::string::const_iterator line_end =
274 find(line_begin, raw_input.end(), '\0'); 274 find(line_begin, raw_input.end(), '\0');
275 // has_headers = true, if there is any data following the status line. 275 // has_headers = true, if there is any data following the status line.
276 // Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0. 276 // Used by ParseStatusLine() to decide if a HTTP/0.9 is really a HTTP/1.0.
277 bool has_headers = line_end != raw_input.end() && 277 bool has_headers = (line_end != raw_input.end() &&
278 (line_end + 1) != raw_input.end() && *(line_end + 1) != '\0'; 278 (line_end + 1) != raw_input.end() &&
279 *(line_end + 1) != '\0');
279 ParseStatusLine(line_begin, line_end, has_headers); 280 ParseStatusLine(line_begin, line_end, has_headers);
280 281
281 if (line_end == raw_input.end()) { 282 if (line_end == raw_input.end()) {
282 raw_headers_.push_back('\0'); 283 raw_headers_.push_back('\0');
283 return; 284 return;
284 } 285 }
285 286
286 // Including a terminating null byte. 287 // Including a terminating null byte.
287 size_t status_line_len = raw_headers_.size(); 288 size_t status_line_len = raw_headers_.size();
288 289
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 std::string::const_iterator first_byte_pos_end = 1113 std::string::const_iterator first_byte_pos_end =
1113 byte_range_resp_spec.begin() + minus_position; 1114 byte_range_resp_spec.begin() + minus_position;
1114 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); 1115 HttpUtil::TrimLWS(&first_byte_pos_begin, &first_byte_pos_end);
1115 1116
1116 bool ok = StringToInt64( 1117 bool ok = StringToInt64(
1117 std::string(first_byte_pos_begin, first_byte_pos_end), 1118 std::string(first_byte_pos_begin, first_byte_pos_end),
1118 first_byte_position); 1119 first_byte_position);
1119 1120
1120 // Obtain last-byte-pos. 1121 // Obtain last-byte-pos.
1121 std::string::const_iterator last_byte_pos_begin = 1122 std::string::const_iterator last_byte_pos_begin =
1122 byte_range_resp_spec.begin() + minus_position + 1; 1123 byte_range_resp_spec.begin() + minus_position + 1;
1123 std::string::const_iterator last_byte_pos_end = 1124 std::string::const_iterator last_byte_pos_end =
1124 byte_range_resp_spec.end(); 1125 byte_range_resp_spec.end();
1125 HttpUtil::TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); 1126 HttpUtil::TrimLWS(&last_byte_pos_begin, &last_byte_pos_end);
1126 1127
1127 ok &= StringToInt64( 1128 ok &= StringToInt64(
1128 std::string(last_byte_pos_begin, last_byte_pos_end), 1129 std::string(last_byte_pos_begin, last_byte_pos_end),
1129 last_byte_position); 1130 last_byte_position);
1130 if (!ok) { 1131 if (!ok) {
1131 *first_byte_position = *last_byte_position = -1; 1132 *first_byte_position = *last_byte_position = -1;
1132 return false; 1133 return false;
1133 } 1134 }
1134 if (*first_byte_position < 0 || *last_byte_position < 0 || 1135 if (*first_byte_position < 0 || *last_byte_position < 0 ||
1135 *first_byte_position > *last_byte_position) 1136 *first_byte_position > *last_byte_position)
1136 return false; 1137 return false;
1137 } else { 1138 } else {
1138 return false; 1139 return false;
1139 } 1140 }
1140 } 1141 }
1141 1142
1142 // Parse the instance-length part. 1143 // Parse the instance-length part.
1143 // If instance-length == "*". 1144 // If instance-length == "*".
1144 std::string::const_iterator instance_length_begin = 1145 std::string::const_iterator instance_length_begin =
1145 content_range_spec.begin() + slash_position + 1; 1146 content_range_spec.begin() + slash_position + 1;
1146 std::string::const_iterator instance_length_end = 1147 std::string::const_iterator instance_length_end =
1147 content_range_spec.end(); 1148 content_range_spec.end();
1148 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end); 1149 HttpUtil::TrimLWS(&instance_length_begin, &instance_length_end);
1149 1150
1150 if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) { 1151 if (LowerCaseEqualsASCII(instance_length_begin, instance_length_end, "*")) {
1151 return false; 1152 return false;
1152 } else if (!StringToInt64( 1153 } else if (!StringToInt64(
1153 std::string(instance_length_begin, instance_length_end), 1154 std::string(instance_length_begin, instance_length_end),
1154 instance_length)) { 1155 instance_length)) {
1155 *instance_length = -1; 1156 *instance_length = -1;
1156 return false; 1157 return false;
1157 } 1158 }
1158 1159
1159 // 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
1160 // response. 1161 // response.
1161 if (*first_byte_position < 0 || *last_byte_position < 0 || 1162 if (*first_byte_position < 0 || *last_byte_position < 0 ||
1162 *instance_length < 0 || *instance_length - 1 < *last_byte_position) 1163 *instance_length < 0 || *instance_length - 1 < *last_byte_position)
1163 return false; 1164 return false;
1164 1165
1165 return true; 1166 return true;
1166 } 1167 }
1167 1168
1168 } // namespace net 1169 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction_unittest.cc ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698