Chromium Code Reviews| 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..01e88b7d200d6e0582e110d461fb1e3d0ace1342 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, |
|
rvargas (doing something else)
2014/07/29 19:21:22
wow, methods are quite out of order in this file :
Adam Rice
2014/07/30 02:00:59
Yes. I probably just made work for you by moving t
|
| + TimeDelta* result) const { |
| + StringPiece name("cache-control"); |
| + std::string value; |
| + |
| + const 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; |