| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 if (!LowerCaseEqualsASCII(it.name(), "range")) | 195 if (!LowerCaseEqualsASCII(it.name(), "range")) |
| 196 continue; | 196 continue; |
| 197 ranges_specifier = it.values(); | 197 ranges_specifier = it.values(); |
| 198 // We just care about the first "Range" header, so break here. | 198 // We just care about the first "Range" header, so break here. |
| 199 break; | 199 break; |
| 200 } | 200 } |
| 201 | 201 |
| 202 if (ranges_specifier.empty()) | 202 if (ranges_specifier.empty()) |
| 203 return false; | 203 return false; |
| 204 | 204 |
| 205 return ParseRangeHeader(ranges_specifier, ranges); |
| 206 } |
| 207 |
| 208 // static |
| 209 bool HttpUtil::ParseRangeHeader(const std::string& ranges_specifier, |
| 210 std::vector<HttpByteRange>* ranges) { |
| 205 size_t equal_char_offset = ranges_specifier.find('='); | 211 size_t equal_char_offset = ranges_specifier.find('='); |
| 206 if (equal_char_offset == std::string::npos) | 212 if (equal_char_offset == std::string::npos) |
| 207 return false; | 213 return false; |
| 208 | 214 |
| 209 // Try to extract bytes-unit part. | 215 // Try to extract bytes-unit part. |
| 210 std::string::const_iterator bytes_unit_begin = ranges_specifier.begin(); | 216 std::string::const_iterator bytes_unit_begin = ranges_specifier.begin(); |
| 211 std::string::const_iterator bytes_unit_end = bytes_unit_begin + | 217 std::string::const_iterator bytes_unit_end = bytes_unit_begin + |
| 212 equal_char_offset; | 218 equal_char_offset; |
| 213 std::string::const_iterator byte_range_set_begin = bytes_unit_end + 1; | 219 std::string::const_iterator byte_range_set_begin = bytes_unit_end + 1; |
| 214 std::string::const_iterator byte_range_set_end = ranges_specifier.end(); | 220 std::string::const_iterator byte_range_set_end = ranges_specifier.end(); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 TrimLWS(&value_begin_, &value_end_); | 687 TrimLWS(&value_begin_, &value_end_); |
| 682 | 688 |
| 683 // bypass empty values. | 689 // bypass empty values. |
| 684 if (value_begin_ != value_end_) | 690 if (value_begin_ != value_end_) |
| 685 return true; | 691 return true; |
| 686 } | 692 } |
| 687 return false; | 693 return false; |
| 688 } | 694 } |
| 689 | 695 |
| 690 } // namespace net | 696 } // namespace net |
| OLD | NEW |