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

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

Issue 10387200: Suppress pause-and-buffer behavior when the HTTP response won't satisfy future requests via cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: %zu is win-unfriendly; use %PRIuS instead. Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_util.h ('k') | webkit/media/buffered_data_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
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
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(HttpVersion version,
704 const std::string& etag_header,
705 const std::string& last_modified_header,
706 const std::string& date_header) {
707 if (version < HttpVersion(1, 1))
708 return false;
709
710 if (!etag_header.empty()) {
711 size_t slash = etag_header.find('/');
712 if (slash == std::string::npos || slash == 0)
713 return true;
714
715 std::string::const_iterator i = etag_header.begin();
716 std::string::const_iterator j = etag_header.begin() + slash;
717 TrimLWS(&i, &j);
718 if (!LowerCaseEqualsASCII(i, j, "w"))
719 return true;
720 }
721
722 base::Time last_modified;
723 if (!base::Time::FromString(last_modified_header.c_str(), &last_modified))
724 return false;
725
726 base::Time date;
727 if (!base::Time::FromString(date_header.c_str(), &date))
728 return false;
729
730 return ((date - last_modified).InSeconds() >= 60);
731 }
732
702 // BNF from section 4.2 of RFC 2616: 733 // BNF from section 4.2 of RFC 2616:
703 // 734 //
704 // message-header = field-name ":" [ field-value ] 735 // message-header = field-name ":" [ field-value ]
705 // field-name = token 736 // field-name = token
706 // field-value = *( field-content | LWS ) 737 // field-value = *( field-content | LWS )
707 // field-content = <the OCTETs making up the field-value 738 // field-content = <the OCTETs making up the field-value
708 // and consisting of either *TEXT or combinations 739 // and consisting of either *TEXT or combinations
709 // of token, separators, and quoted-string> 740 // of token, separators, and quoted-string>
710 // 741 //
711 742
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 value_is_quoted_ = true; 889 value_is_quoted_ = true;
859 // Do not store iterators into this. See declaration of unquoted_value_. 890 // Do not store iterators into this. See declaration of unquoted_value_.
860 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_); 891 unquoted_value_ = HttpUtil::Unquote(value_begin_, value_end_);
861 } 892 }
862 } 893 }
863 894
864 return true; 895 return true;
865 } 896 }
866 897
867 } // namespace net 898 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_util.h ('k') | webkit/media/buffered_data_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698