| 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 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 return; | 731 return; |
| 732 if (HttpUtil::HasHeader(*headers, header_name)) | 732 if (HttpUtil::HasHeader(*headers, header_name)) |
| 733 return; | 733 return; |
| 734 *headers += std::string(header_name) + ": " + header_value + "\r\n"; | 734 *headers += std::string(header_name) + ": " + header_value + "\r\n"; |
| 735 } | 735 } |
| 736 | 736 |
| 737 bool HttpUtil::HasStrongValidators(HttpVersion version, | 737 bool HttpUtil::HasStrongValidators(HttpVersion version, |
| 738 const std::string& etag_header, | 738 const std::string& etag_header, |
| 739 const std::string& last_modified_header, | 739 const std::string& last_modified_header, |
| 740 const std::string& date_header) { | 740 const std::string& date_header) { |
| 741 if (!HasValidators(version, etag_header, last_modified_header)) |
| 742 return false; |
| 743 |
| 741 if (version < HttpVersion(1, 1)) | 744 if (version < HttpVersion(1, 1)) |
| 742 return false; | 745 return false; |
| 743 | 746 |
| 744 if (!etag_header.empty()) { | 747 if (!etag_header.empty()) { |
| 745 size_t slash = etag_header.find('/'); | 748 size_t slash = etag_header.find('/'); |
| 746 if (slash == std::string::npos || slash == 0) | 749 if (slash == std::string::npos || slash == 0) |
| 747 return true; | 750 return true; |
| 748 | 751 |
| 749 std::string::const_iterator i = etag_header.begin(); | 752 std::string::const_iterator i = etag_header.begin(); |
| 750 std::string::const_iterator j = etag_header.begin() + slash; | 753 std::string::const_iterator j = etag_header.begin() + slash; |
| 751 TrimLWS(&i, &j); | 754 TrimLWS(&i, &j); |
| 752 if (!base::LowerCaseEqualsASCII(base::StringPiece(i, j), "w")) | 755 if (!base::LowerCaseEqualsASCII(base::StringPiece(i, j), "w")) |
| 753 return true; | 756 return true; |
| 754 } | 757 } |
| 755 | 758 |
| 756 base::Time last_modified; | 759 base::Time last_modified; |
| 757 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified)) | 760 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified)) |
| 758 return false; | 761 return false; |
| 759 | 762 |
| 760 base::Time date; | 763 base::Time date; |
| 761 if (!base::Time::FromString(date_header.c_str(), &date)) | 764 if (!base::Time::FromString(date_header.c_str(), &date)) |
| 762 return false; | 765 return false; |
| 763 | 766 |
| 767 // Last-Modified is implicitly weak unless it is at least 60 seconds before |
| 768 // the Date value. |
| 764 return ((date - last_modified).InSeconds() >= 60); | 769 return ((date - last_modified).InSeconds() >= 60); |
| 765 } | 770 } |
| 766 | 771 |
| 772 bool HttpUtil::HasValidators(HttpVersion version, |
| 773 const std::string& etag_header, |
| 774 const std::string& last_modified_header) { |
| 775 if (version < HttpVersion(1, 0)) |
| 776 return false; |
| 777 |
| 778 base::Time last_modified; |
| 779 if (base::Time::FromString(last_modified_header.c_str(), &last_modified)) |
| 780 return true; |
| 781 |
| 782 // It is OK to consider an empty string in etag_header to be a missing header |
| 783 // since valid ETags are always quoted-strings (see RFC 2616 3.11) and thus |
| 784 // empty ETags aren't empty strings (i.e., an empty ETag might be "\"\""). |
| 785 return version >= HttpVersion(1, 1) && !etag_header.empty(); |
| 786 } |
| 787 |
| 767 // Functions for histogram initialization. The code 0 is put in the map to | 788 // Functions for histogram initialization. The code 0 is put in the map to |
| 768 // track status codes that are invalid. | 789 // track status codes that are invalid. |
| 769 // TODO(gavinp): Greatly prune the collected codes once we learn which | 790 // TODO(gavinp): Greatly prune the collected codes once we learn which |
| 770 // ones are not sent in practice, to reduce upload size & memory use. | 791 // ones are not sent in practice, to reduce upload size & memory use. |
| 771 | 792 |
| 772 enum { | 793 enum { |
| 773 HISTOGRAM_MIN_HTTP_STATUS_CODE = 100, | 794 HISTOGRAM_MIN_HTTP_STATUS_CODE = 100, |
| 774 HISTOGRAM_MAX_HTTP_STATUS_CODE = 599, | 795 HISTOGRAM_MAX_HTTP_STATUS_CODE = 599, |
| 775 }; | 796 }; |
| 776 | 797 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 value_is_quoted_ = true; | 987 value_is_quoted_ = true; |
| 967 // Do not store iterators into this. See declaration of unquoted_value_. | 988 // Do not store iterators into this. See declaration of unquoted_value_. |
| 968 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 989 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
| 969 } | 990 } |
| 970 } | 991 } |
| 971 | 992 |
| 972 return true; | 993 return true; |
| 973 } | 994 } |
| 974 | 995 |
| 975 } // namespace net | 996 } // namespace net |
| OLD | NEW |