Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 parsing content-types were borrowed from Firefox: | 5 // The rules for parsing content-types were borrowed from Firefox: |
| 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 | 6 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 |
| 7 | 7 |
| 8 #include "net/http/http_util.h" | 8 #include "net/http/http_util.h" |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 size_t space_position = content_range_spec.find(' '); | 281 size_t space_position = content_range_spec.find(' '); |
| 282 if (space_position == base::StringPiece::npos) | 282 if (space_position == base::StringPiece::npos) |
| 283 return false; | 283 return false; |
| 284 | 284 |
| 285 // Invalid header if it doesn't contain "bytes-unit". | 285 // Invalid header if it doesn't contain "bytes-unit". |
| 286 if (!base::LowerCaseEqualsASCII( | 286 if (!base::LowerCaseEqualsASCII( |
| 287 TrimLWS(content_range_spec.substr(0, space_position)), "bytes")) { | 287 TrimLWS(content_range_spec.substr(0, space_position)), "bytes")) { |
| 288 return false; | 288 return false; |
| 289 } | 289 } |
| 290 | 290 |
| 291 size_t slash_position = content_range_spec.find('/', space_position + 1); | 291 size_t minus_position = content_range_spec.find('-', space_position + 1); |
| 292 if (minus_position == base::StringPiece::npos) | |
| 293 return false; | |
| 294 size_t slash_position = content_range_spec.find('/', minus_position + 1); | |
| 292 if (slash_position == base::StringPiece::npos) | 295 if (slash_position == base::StringPiece::npos) |
| 293 return false; | 296 return false; |
| 294 | 297 |
| 295 // Obtain the part behind the space and before slash. | 298 if (base::StringToInt64( |
| 296 base::StringPiece byte_range_resp_spec = TrimLWS(content_range_spec.substr( | 299 TrimLWS(content_range_spec.substr( |
| 297 space_position + 1, slash_position - (space_position + 1))); | 300 space_position + 1, minus_position - (space_position + 1))), |
| 298 | 301 first_byte_position) && |
| 299 if (byte_range_resp_spec != "*") { | 302 *first_byte_position >= 0 && |
| 300 size_t minus_position = byte_range_resp_spec.find('-'); | 303 base::StringToInt64( |
| 301 if (minus_position == base::StringPiece::npos) | 304 TrimLWS(content_range_spec.substr( |
| 302 return false; | 305 minus_position + 1, slash_position - (minus_position + 1))), |
| 303 | 306 last_byte_position) && |
| 304 // Obtain first-byte-pos and last-byte-pos. | 307 *last_byte_position >= *first_byte_position && |
| 305 if (!base::StringToInt64( | 308 base::StringToInt64( |
| 306 TrimLWS(byte_range_resp_spec.substr(0, minus_position)), | 309 TrimLWS(content_range_spec.substr(slash_position + 1)), |
| 307 first_byte_position) || | 310 instance_length) && |
| 308 !base::StringToInt64( | 311 *instance_length > *last_byte_position) { |
| 309 TrimLWS(byte_range_resp_spec.substr(minus_position + 1)), | 312 return true; |
| 310 last_byte_position)) { | |
| 311 *first_byte_position = *last_byte_position = -1; | |
| 312 return false; | |
| 313 } | |
| 314 if (*first_byte_position < 0 || *last_byte_position < 0 || | |
| 315 *first_byte_position > *last_byte_position) | |
| 316 return false; | |
| 317 } | 313 } |
|
mmenke
2016/12/06 19:18:06
nit: Suggest a blank line here.
| |
| 318 | 314 *first_byte_position = *last_byte_position = *instance_length = -1; |
| 319 // Parse the instance-length part. | 315 return false; |
| 320 base::StringPiece instance_length_spec = | |
| 321 TrimLWS(content_range_spec.substr(slash_position + 1)); | |
| 322 | |
| 323 if (base::StartsWith(instance_length_spec, "*", | |
| 324 base::CompareCase::SENSITIVE)) { | |
| 325 return false; | |
| 326 } else if (!base::StringToInt64(instance_length_spec, instance_length)) { | |
| 327 *instance_length = -1; | |
| 328 return false; | |
| 329 } | |
| 330 | |
| 331 // We have all the values; let's verify that they make sense for a 206 | |
| 332 // response. | |
| 333 if (*first_byte_position < 0 || *last_byte_position < 0 || | |
| 334 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | |
| 335 return false; | |
| 336 | |
| 337 return true; | |
| 338 } | 316 } |
| 339 | 317 |
| 340 // static | 318 // static |
| 341 bool HttpUtil::ParseRetryAfterHeader(const std::string& retry_after_string, | 319 bool HttpUtil::ParseRetryAfterHeader(const std::string& retry_after_string, |
| 342 base::Time now, | 320 base::Time now, |
| 343 base::TimeDelta* retry_after) { | 321 base::TimeDelta* retry_after) { |
| 344 int seconds; | 322 int seconds; |
| 345 base::Time time; | 323 base::Time time; |
| 346 base::TimeDelta interval; | 324 base::TimeDelta interval; |
| 347 | 325 |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1146 return true; | 1124 return true; |
| 1147 } | 1125 } |
| 1148 | 1126 |
| 1149 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const { | 1127 bool HttpUtil::NameValuePairsIterator::IsQuote(char c) const { |
| 1150 if (strict_quotes_) | 1128 if (strict_quotes_) |
| 1151 return c == '"'; | 1129 return c == '"'; |
| 1152 return HttpUtil::IsQuote(c); | 1130 return HttpUtil::IsQuote(c); |
| 1153 } | 1131 } |
| 1154 | 1132 |
| 1155 } // namespace net | 1133 } // namespace net |
| OLD | NEW |