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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 268 |
269 // Do a final check on the HttpByteRange object. | 269 // Do a final check on the HttpByteRange object. |
270 if (!range.IsValid()) | 270 if (!range.IsValid()) |
271 return false; | 271 return false; |
272 ranges->push_back(range); | 272 ranges->push_back(range); |
273 } | 273 } |
274 return !ranges->empty(); | 274 return !ranges->empty(); |
275 } | 275 } |
276 | 276 |
277 // static | 277 // static |
| 278 bool HttpUtil::ParseRetryAfterHeader(const std::string& retry_after_string, |
| 279 base::Time now, |
| 280 base::TimeDelta* retry_after) { |
| 281 int seconds; |
| 282 base::Time time; |
| 283 base::TimeDelta interval; |
| 284 |
| 285 if (base::StringToInt(retry_after_string, &seconds)) { |
| 286 interval = base::TimeDelta::FromSeconds(seconds); |
| 287 } else if (base::Time::FromUTCString(retry_after_string.c_str(), &time)) { |
| 288 interval = time - now; |
| 289 } else { |
| 290 return false; |
| 291 } |
| 292 |
| 293 if (interval < base::TimeDelta::FromSeconds(0)) |
| 294 return false; |
| 295 |
| 296 *retry_after = interval; |
| 297 return true; |
| 298 } |
| 299 |
| 300 // static |
278 bool HttpUtil::HasHeader(const std::string& headers, const char* name) { | 301 bool HttpUtil::HasHeader(const std::string& headers, const char* name) { |
279 size_t name_len = strlen(name); | 302 size_t name_len = strlen(name); |
280 std::string::const_iterator it = | 303 std::string::const_iterator it = |
281 std::search(headers.begin(), | 304 std::search(headers.begin(), |
282 headers.end(), | 305 headers.end(), |
283 name, | 306 name, |
284 name + name_len, | 307 name + name_len, |
285 base::CaseInsensitiveCompareASCII<char>()); | 308 base::CaseInsensitiveCompareASCII<char>()); |
286 if (it == headers.end()) | 309 if (it == headers.end()) |
287 return false; | 310 return false; |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 value_is_quoted_ = true; | 934 value_is_quoted_ = true; |
912 // Do not store iterators into this. See declaration of unquoted_value_. | 935 // Do not store iterators into this. See declaration of unquoted_value_. |
913 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 936 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
914 } | 937 } |
915 } | 938 } |
916 | 939 |
917 return true; | 940 return true; |
918 } | 941 } |
919 | 942 |
920 } // namespace net | 943 } // namespace net |
OLD | NEW |