summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 02:15:33 +0000
committerfischman@chromium.org <fischman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-25 02:15:33 +0000
commitb314d4bc349fbf8e41e8a924f130757fb68a202c (patch)
tree9e2a1df530c634ca0732e55f5dc7c9aa3465e080 /net
parent99de53e244b78b4f6d9698c0855afa01773e94c1 (diff)
downloadchromium_src-b314d4bc349fbf8e41e8a924f130757fb68a202c.zip
chromium_src-b314d4bc349fbf8e41e8a924f130757fb68a202c.tar.gz
chromium_src-b314d4bc349fbf8e41e8a924f130757fb68a202c.tar.bz2
Suppress pause-and-buffer behavior when the HTTP response won't satisfy future requests via cache.
BUG=123074 Review URL: https://chromiumcodereview.appspot.com/10387200 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/http/http_response_headers.cc36
-rw-r--r--net/http/http_util.cc31
-rw-r--r--net/http/http_util.h8
3 files changed, 49 insertions, 26 deletions
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 33d78da..c03fbe9 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -1160,32 +1160,16 @@ bool HttpResponseHeaders::IsKeepAlive() const {
}
bool HttpResponseHeaders::HasStrongValidators() const {
- if (GetHttpVersion() < HttpVersion(1, 1))
- return false;
-
- std::string etag_value;
- EnumerateHeader(NULL, "etag", &etag_value);
- if (!etag_value.empty()) {
- size_t slash = etag_value.find('/');
- if (slash == std::string::npos || slash == 0)
- return true;
-
- std::string::const_iterator i = etag_value.begin();
- std::string::const_iterator j = etag_value.begin() + slash;
- HttpUtil::TrimLWS(&i, &j);
- if (!LowerCaseEqualsASCII(i, j, "w"))
- return true;
- }
-
- Time last_modified;
- if (!GetLastModifiedValue(&last_modified))
- return false;
-
- Time date;
- if (!GetDateValue(&date))
- return false;
-
- return ((date - last_modified).InSeconds() >= 60);
+ std::string etag_header;
+ EnumerateHeader(NULL, "etag", &etag_header);
+ std::string last_modified_header;
+ EnumerateHeader(NULL, "Last-Modified", &last_modified_header);
+ std::string date_header;
+ EnumerateHeader(NULL, "Date", &date_header);
+ return HttpUtil::HasStrongValidators(GetHttpVersion(),
+ etag_header,
+ last_modified_header,
+ date_header);
}
// From RFC 2616:
diff --git a/net/http/http_util.cc b/net/http/http_util.cc
index a5dc391..0a9c6a6 100644
--- a/net/http/http_util.cc
+++ b/net/http/http_util.cc
@@ -15,6 +15,7 @@
#include "base/string_number_conversions.h"
#include "base/string_piece.h"
#include "base/string_util.h"
+#include "base/time.h"
using std::string;
@@ -699,6 +700,36 @@ void HttpUtil::AppendHeaderIfMissing(const char* header_name,
*headers += std::string(header_name) + ": " + header_value + "\r\n";
}
+bool HttpUtil::HasStrongValidators(HttpVersion version,
+ const std::string& etag_header,
+ const std::string& last_modified_header,
+ const std::string& date_header) {
+ if (version < HttpVersion(1, 1))
+ return false;
+
+ if (!etag_header.empty()) {
+ size_t slash = etag_header.find('/');
+ if (slash == std::string::npos || slash == 0)
+ return true;
+
+ std::string::const_iterator i = etag_header.begin();
+ std::string::const_iterator j = etag_header.begin() + slash;
+ TrimLWS(&i, &j);
+ if (!LowerCaseEqualsASCII(i, j, "w"))
+ return true;
+ }
+
+ base::Time last_modified;
+ if (!base::Time::FromString(last_modified_header.c_str(), &last_modified))
+ return false;
+
+ base::Time date;
+ if (!base::Time::FromString(date_header.c_str(), &date))
+ return false;
+
+ return ((date - last_modified).InSeconds() >= 60);
+}
+
// BNF from section 4.2 of RFC 2616:
//
// message-header = field-name ":" [ field-value ]
diff --git a/net/http/http_util.h b/net/http/http_util.h
index 57aa0d0..0801382 100644
--- a/net/http/http_util.h
+++ b/net/http/http_util.h
@@ -14,6 +14,7 @@
#include "googleurl/src/gurl.h"
#include "net/base/net_export.h"
#include "net/http/http_byte_range.h"
+#include "net/http/http_version.h"
// This is a macro to support extending this string literal at compile time.
// Please excuse me polluting your global namespace!
@@ -187,6 +188,13 @@ class NET_EXPORT HttpUtil {
const std::string& header_value,
std::string* headers);
+ // Returns true if the parameters describe a response with a strong etag or
+ // last-modified header. See section 13.3.3 of RFC 2616.
+ static bool HasStrongValidators(HttpVersion version,
+ const std::string& etag_header,
+ const std::string& last_modified_header,
+ const std::string& date_header);
+
// Used to iterate over the name/value pairs of HTTP headers. To iterate
// over the values in a multi-value header, use ValuesIterator.
// See AssembleRawHeaders for joining line continuations (this iterator