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

Unified Diff: net/http/http_response_headers.cc

Issue 391763002: Initial implementation of Chrome-Freshness header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove const from directive_size. Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index b7ef98a5980633485902bdf522dbb77e2a5c0f02..e767ebb4fcd2900cb976b77a00ee828b3c4fd4b7 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -753,6 +753,32 @@ size_t HttpResponseHeaders::FindHeader(size_t from,
return std::string::npos;
}
+bool HttpResponseHeaders::GetCacheControlDirective(const StringPiece& directive,
+ TimeDelta* result) const {
+ StringPiece name("cache-control");
+ std::string value;
+
+ size_t directive_size = directive.size();
+
+ void* iter = NULL;
+ while (EnumerateHeader(&iter, name, &value)) {
+ if (value.size() > directive_size + 1 &&
+ LowerCaseEqualsASCII(value.begin(),
+ value.begin() + directive_size,
+ directive.begin()) &&
+ value[directive_size] == '=') {
+ int64 seconds;
+ base::StringToInt64(
+ StringPiece(value.begin() + directive_size + 1, value.end()),
+ &seconds);
+ *result = TimeDelta::FromSeconds(seconds);
+ return true;
+ }
+ }
+
+ return false;
+}
+
void HttpResponseHeaders::AddHeader(std::string::const_iterator name_begin,
std::string::const_iterator name_end,
std::string::const_iterator values_begin,
@@ -1092,29 +1118,7 @@ TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time,
}
bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const {
- std::string name = "cache-control";
- std::string value;
-
- const char kMaxAgePrefix[] = "max-age=";
- const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
-
- void* iter = NULL;
- while (EnumerateHeader(&iter, name, &value)) {
- if (value.size() > kMaxAgePrefixLen) {
- if (LowerCaseEqualsASCII(value.begin(),
- value.begin() + kMaxAgePrefixLen,
- kMaxAgePrefix)) {
- int64 seconds;
- base::StringToInt64(StringPiece(value.begin() + kMaxAgePrefixLen,
- value.end()),
- &seconds);
- *result = TimeDelta::FromSeconds(seconds);
- return true;
- }
- }
- }
-
- return false;
+ return GetCacheControlDirective("max-age", result);
}
bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const {
@@ -1140,6 +1144,11 @@ bool HttpResponseHeaders::GetExpiresValue(Time* result) const {
return GetTimeValuedHeader("Expires", result);
}
+bool HttpResponseHeaders::GetStaleWhileRevalidateValue(
+ TimeDelta* result) const {
+ return GetCacheControlDirective("stale-while-revalidate", result);
+}
+
bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name,
Time* result) const {
std::string value;
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698