Chromium Code Reviews| 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" | 12 #include "base/basictypes.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/time.h" | |
| 18 | 19 |
| 19 using std::string; | 20 using std::string; |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 //----------------------------------------------------------------------------- | 24 //----------------------------------------------------------------------------- |
| 24 | 25 |
| 25 // Return the index of the closing quote of the string, if any. | 26 // Return the index of the closing quote of the string, if any. |
| 26 static size_t FindStringEnd(const string& line, size_t start, char delim) { | 27 static size_t FindStringEnd(const string& line, size_t start, char delim) { |
| 27 DCHECK(start < line.length() && line[start] == delim && | 28 DCHECK(start < line.length() && line[start] == delim && |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 void HttpUtil::AppendHeaderIfMissing(const char* header_name, | 693 void HttpUtil::AppendHeaderIfMissing(const char* header_name, |
| 693 const std::string& header_value, | 694 const std::string& header_value, |
| 694 std::string* headers) { | 695 std::string* headers) { |
| 695 if (header_value.empty()) | 696 if (header_value.empty()) |
| 696 return; | 697 return; |
| 697 if (net::HttpUtil::HasHeader(*headers, header_name)) | 698 if (net::HttpUtil::HasHeader(*headers, header_name)) |
| 698 return; | 699 return; |
| 699 *headers += std::string(header_name) + ": " + header_value + "\r\n"; | 700 *headers += std::string(header_name) + ": " + header_value + "\r\n"; |
| 700 } | 701 } |
| 701 | 702 |
| 703 bool HttpUtil::HasStrongValidators( | |
| 704 HttpVersion version, | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: arguments should start on the previous line.
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
No, because that makes the second & subsequent arg
rvargas (doing something else)
2012/05/23 18:26:09
(warning, rietveld may ruin formatting)
bool Http
Ami GONE FROM CHROMIUM
2012/05/23 19:29:51
Ah; I thought you were asking for mixed style, bec
| |
| 705 const std::string& etag_header, | |
| 706 const std::string& last_modified_header, | |
| 707 const std::string& date_header) { | |
| 708 if (version < HttpVersion(1, 1)) | |
| 709 return false; | |
| 710 | |
| 711 if (!etag_header.empty()) { | |
| 712 size_t slash = etag_header.find('/'); | |
| 713 if (slash == std::string::npos || slash == 0) | |
| 714 return true; | |
| 715 | |
| 716 std::string::const_iterator i = etag_header.begin(); | |
| 717 std::string::const_iterator j = etag_header.begin() + slash; | |
| 718 TrimLWS(&i, &j); | |
| 719 if (!LowerCaseEqualsASCII(i, j, "w")) | |
| 720 return true; | |
| 721 } | |
| 722 | |
| 723 base::Time last_modified; | |
| 724 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified)) | |
| 725 return false; | |
| 726 | |
| 727 base::Time date; | |
| 728 if (!base::Time::FromString(date_header.c_str(), &date)) | |
| 729 return false; | |
| 730 | |
| 731 return ((date - last_modified).InSeconds() >= 60); | |
| 732 } | |
| 733 | |
| 702 // BNF from section 4.2 of RFC 2616: | 734 // BNF from section 4.2 of RFC 2616: |
| 703 // | 735 // |
| 704 // message-header = field-name ":" [ field-value ] | 736 // message-header = field-name ":" [ field-value ] |
| 705 // field-name = token | 737 // field-name = token |
| 706 // field-value = *( field-content | LWS ) | 738 // field-value = *( field-content | LWS ) |
| 707 // field-content = <the OCTETs making up the field-value | 739 // field-content = <the OCTETs making up the field-value |
| 708 // and consisting of either *TEXT or combinations | 740 // and consisting of either *TEXT or combinations |
| 709 // of token, separators, and quoted-string> | 741 // of token, separators, and quoted-string> |
| 710 // | 742 // |
| 711 | 743 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 value_is_quoted_ = true; | 890 value_is_quoted_ = true; |
| 859 // Do not store iterators into this. See declaration of unquoted_value_. | 891 // Do not store iterators into this. See declaration of unquoted_value_. |
| 860 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); | 892 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); |
| 861 } | 893 } |
| 862 } | 894 } |
| 863 | 895 |
| 864 return true; | 896 return true; |
| 865 } | 897 } |
| 866 | 898 |
| 867 } // namespace net | 899 } // namespace net |
| OLD | NEW |