Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: net/http/http_util.cc

Issue 1481143002: Added HttpUtils::HasValidators and HttpResponse::HasValidators (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed loops from the test cases Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 if (header_value.empty()) 730 if (header_value.empty())
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) {
gavinp 2016/02/25 18:56:20 Could HasStrongValidators call HasValidators?
jamartin 2016/02/26 14:47:50 Sure although it won't make any difference in the
gavinp 2016/02/26 15:32:59 The documentary purpose was the only one; but it f
741 if (version < HttpVersion(1, 1)) 741 if (version < HttpVersion(1, 1))
742 return false; 742 return false;
743 743
744 if (!etag_header.empty()) { 744 if (!etag_header.empty()) {
745 size_t slash = etag_header.find('/'); 745 size_t slash = etag_header.find('/');
746 if (slash == std::string::npos || slash == 0) 746 if (slash == std::string::npos || slash == 0)
747 return true; 747 return true;
748 748
749 std::string::const_iterator i = etag_header.begin(); 749 std::string::const_iterator i = etag_header.begin();
750 std::string::const_iterator j = etag_header.begin() + slash; 750 std::string::const_iterator j = etag_header.begin() + slash;
751 TrimLWS(&i, &j); 751 TrimLWS(&i, &j);
752 if (!base::LowerCaseEqualsASCII(base::StringPiece(i, j), "w")) 752 if (!base::LowerCaseEqualsASCII(base::StringPiece(i, j), "w"))
753 return true; 753 return true;
754 } 754 }
755 755
756 base::Time last_modified; 756 base::Time last_modified;
757 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified)) 757 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified))
758 return false; 758 return false;
759 759
760 base::Time date; 760 base::Time date;
761 if (!base::Time::FromString(date_header.c_str(), &date)) 761 if (!base::Time::FromString(date_header.c_str(), &date))
762 return false; 762 return false;
763 763
764 // Last-Modified is implicitly weak unless it is at least 60 seconds before
765 // the Date value.
764 return ((date - last_modified).InSeconds() >= 60); 766 return ((date - last_modified).InSeconds() >= 60);
765 } 767 }
766 768
769 bool HttpUtil::HasValidators(HttpVersion version,
770 const std::string& etag_header,
771 const std::string& last_modified_header) {
772 if (version < HttpVersion(1, 0))
773 return false;
774
775 base::Time last_modified;
776 if (base::Time::FromString(last_modified_header.c_str(), &last_modified))
777 return true;
778
779 return version >= HttpVersion(1, 1) && !etag_header.empty();
780 }
781
767 // Functions for histogram initialization. The code 0 is put in the map to 782 // Functions for histogram initialization. The code 0 is put in the map to
768 // track status codes that are invalid. 783 // track status codes that are invalid.
769 // TODO(gavinp): Greatly prune the collected codes once we learn which 784 // TODO(gavinp): Greatly prune the collected codes once we learn which
770 // ones are not sent in practice, to reduce upload size & memory use. 785 // ones are not sent in practice, to reduce upload size & memory use.
771 786
772 enum { 787 enum {
773 HISTOGRAM_MIN_HTTP_STATUS_CODE = 100, 788 HISTOGRAM_MIN_HTTP_STATUS_CODE = 100,
774 HISTOGRAM_MAX_HTTP_STATUS_CODE = 599, 789 HISTOGRAM_MAX_HTTP_STATUS_CODE = 599,
775 }; 790 };
776 791
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 value_is_quoted_ = true; 981 value_is_quoted_ = true;
967 // Do not store iterators into this. See declaration of unquoted_value_. 982 // Do not store iterators into this. See declaration of unquoted_value_.
968 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 983 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
969 } 984 }
970 } 985 }
971 986
972 return true; 987 return true;
973 } 988 }
974 989
975 } // namespace net 990 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698