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> |
11 | 11 |
12 #include "base/basictypes.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
16 #include "base/strings/string_tokenizer.h" | 15 #include "base/strings/string_tokenizer.h" |
17 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
19 #include "base/time/time.h" | 18 #include "base/time/time.h" |
20 | 19 |
21 | |
22 namespace net { | 20 namespace net { |
23 | 21 |
24 // Helpers -------------------------------------------------------------------- | 22 // Helpers -------------------------------------------------------------------- |
25 | 23 |
26 // Returns the index of the closing quote of the string, if any. |start| points | 24 // Returns the index of the closing quote of the string, if any. |start| points |
27 // at the opening quote. | 25 // at the opening quote. |
28 static size_t FindStringEnd(const std::string& line, size_t start, char delim) { | 26 static size_t FindStringEnd(const std::string& line, size_t start, char delim) { |
29 DCHECK_LT(start, line.length()); | 27 DCHECK_LT(start, line.length()); |
30 DCHECK_EQ(line[start], delim); | 28 DCHECK_EQ(line[start], delim); |
31 DCHECK((delim == '"') || (delim == '\'')); | 29 DCHECK((delim == '"') || (delim == '\'')); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 std::string::const_iterator first_byte_pos_begin = | 201 std::string::const_iterator first_byte_pos_begin = |
204 byte_range_set_iterator.value_begin(); | 202 byte_range_set_iterator.value_begin(); |
205 std::string::const_iterator first_byte_pos_end = | 203 std::string::const_iterator first_byte_pos_end = |
206 first_byte_pos_begin + minus_char_offset; | 204 first_byte_pos_begin + minus_char_offset; |
207 TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); | 205 TrimLWS(&first_byte_pos_begin, &first_byte_pos_end); |
208 std::string first_byte_pos(first_byte_pos_begin, first_byte_pos_end); | 206 std::string first_byte_pos(first_byte_pos_begin, first_byte_pos_end); |
209 | 207 |
210 HttpByteRange range; | 208 HttpByteRange range; |
211 // Try to obtain first-byte-pos. | 209 // Try to obtain first-byte-pos. |
212 if (!first_byte_pos.empty()) { | 210 if (!first_byte_pos.empty()) { |
213 int64 first_byte_position = -1; | 211 int64_t first_byte_position = -1; |
214 if (!base::StringToInt64(first_byte_pos, &first_byte_position)) | 212 if (!base::StringToInt64(first_byte_pos, &first_byte_position)) |
215 return false; | 213 return false; |
216 range.set_first_byte_position(first_byte_position); | 214 range.set_first_byte_position(first_byte_position); |
217 } | 215 } |
218 | 216 |
219 std::string::const_iterator last_byte_pos_begin = | 217 std::string::const_iterator last_byte_pos_begin = |
220 byte_range_set_iterator.value_begin() + minus_char_offset + 1; | 218 byte_range_set_iterator.value_begin() + minus_char_offset + 1; |
221 std::string::const_iterator last_byte_pos_end = | 219 std::string::const_iterator last_byte_pos_end = |
222 byte_range_set_iterator.value_end(); | 220 byte_range_set_iterator.value_end(); |
223 TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); | 221 TrimLWS(&last_byte_pos_begin, &last_byte_pos_end); |
224 std::string last_byte_pos(last_byte_pos_begin, last_byte_pos_end); | 222 std::string last_byte_pos(last_byte_pos_begin, last_byte_pos_end); |
225 | 223 |
226 // We have last-byte-pos or suffix-byte-range-spec in this case. | 224 // We have last-byte-pos or suffix-byte-range-spec in this case. |
227 if (!last_byte_pos.empty()) { | 225 if (!last_byte_pos.empty()) { |
228 int64 last_byte_position; | 226 int64_t last_byte_position; |
229 if (!base::StringToInt64(last_byte_pos, &last_byte_position)) | 227 if (!base::StringToInt64(last_byte_pos, &last_byte_position)) |
230 return false; | 228 return false; |
231 if (range.HasFirstBytePosition()) | 229 if (range.HasFirstBytePosition()) |
232 range.set_last_byte_position(last_byte_position); | 230 range.set_last_byte_position(last_byte_position); |
233 else | 231 else |
234 range.set_suffix_length(last_byte_position); | 232 range.set_suffix_length(last_byte_position); |
235 } else if (!range.HasFirstBytePosition()) { | 233 } else if (!range.HasFirstBytePosition()) { |
236 return false; | 234 return false; |
237 } | 235 } |
238 | 236 |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 value_is_quoted_ = true; | 939 value_is_quoted_ = true; |
942 // Do not store iterators into this. See declaration of unquoted_value_. | 940 // Do not store iterators into this. See declaration of unquoted_value_. |
943 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 941 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
944 } | 942 } |
945 } | 943 } |
946 | 944 |
947 return true; | 945 return true; |
948 } | 946 } |
949 | 947 |
950 } // namespace net | 948 } // namespace net |
OLD | NEW |