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

Side by Side Diff: net/http/http_response_headers.h

Issue 455623003: stale-while-revalidate experimental implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetFreshnessLifetimes now returns two times. Duplicate AsyncValidations for the same URL are discar… Created 6 years, 3 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
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 #ifndef NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 5 #ifndef NET_HTTP_HTTP_RESPONSE_HEADERS_H_
6 #define NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 6 #define NET_HTTP_HTTP_RESPONSE_HEADERS_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 21
22 namespace base { 22 namespace base {
23 class Time; 23 class Time;
24 class TimeDelta; 24 class TimeDelta;
25 } 25 }
26 26
27 namespace net { 27 namespace net {
28 28
29 class HttpByteRange; 29 class HttpByteRange;
30 30
31 enum ValidationType {
32 VALIDATION_NONE = 0, // the resource is fresh
rvargas (doing something else) 2014/09/11 02:33:07 nit: Start with uppercase and period at the end.
Adam Rice 2014/09/12 01:46:49 Done.
33 VALIDATION_ASYNCHRONOUS, // the resource requires async revalidation
34 VALIDATION_SYNCHRONOUS // the resource requires sync revalidation
35 };
36
31 // HttpResponseHeaders: parses and holds HTTP response headers. 37 // HttpResponseHeaders: parses and holds HTTP response headers.
32 class NET_EXPORT HttpResponseHeaders 38 class NET_EXPORT HttpResponseHeaders
33 : public base::RefCountedThreadSafe<HttpResponseHeaders> { 39 : public base::RefCountedThreadSafe<HttpResponseHeaders> {
34 public: 40 public:
35 // Persist options. 41 // Persist options.
36 typedef int PersistOptions; 42 typedef int PersistOptions;
37 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers. 43 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers.
38 static const PersistOptions PERSIST_ALL = 0; // Parsed headers. 44 static const PersistOptions PERSIST_ALL = 0; // Parsed headers.
39 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0; 45 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0;
40 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1; 46 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1;
41 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2; 47 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2;
42 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3; 48 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3;
43 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4; 49 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4;
44 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5; 50 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5;
45 51
52 struct FreshnessLifetimes {
53 // Initialise |fresh| and set |stale| to 0.
rvargas (doing something else) 2014/09/11 02:33:07 Can we get rid of constructors and destructors? It
Adam Rice 2014/09/12 01:46:49 Done.
54 explicit FreshnessLifetimes(const base::TimeDelta& fresh);
55 // Initialise both fields to zero.
56 FreshnessLifetimes();
57 ~FreshnessLifetimes();
58
59 // How long the resource will be fresh for.
60 base::TimeDelta fresh;
61 // How long after becoming not fresh that the resource will be usable stale
rvargas (doing something else) 2014/09/11 02:33:07 Suggestion: "... not fresh the resource will be st
Adam Rice 2014/09/12 01:46:49 Done.
62 // (if async revalidation is enabled).
63 base::TimeDelta stale;
64 };
65
46 static const char kContentRange[]; 66 static const char kContentRange[];
47 67
48 // Parses the given raw_headers. raw_headers should be formatted thus: 68 // Parses the given raw_headers. raw_headers should be formatted thus:
49 // includes the http status response line, each line is \0-terminated, and 69 // includes the http status response line, each line is \0-terminated, and
50 // it's terminated by an empty line (ie, 2 \0s in a row). 70 // it's terminated by an empty line (ie, 2 \0s in a row).
51 // (Note that line continuations should have already been joined; 71 // (Note that line continuations should have already been joined;
52 // see HttpUtil::AssembleRawHeaders) 72 // see HttpUtil::AssembleRawHeaders)
53 // 73 //
54 // HttpResponseHeaders does not perform any encoding changes on the input. 74 // HttpResponseHeaders does not perform any encoding changes on the input.
55 // 75 //
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool GetCharset(std::string* charset) const; 214 bool GetCharset(std::string* charset) const;
195 215
196 // Returns true if this response corresponds to a redirect. The target 216 // Returns true if this response corresponds to a redirect. The target
197 // location of the redirect is optionally returned if location is non-null. 217 // location of the redirect is optionally returned if location is non-null.
198 bool IsRedirect(std::string* location) const; 218 bool IsRedirect(std::string* location) const;
199 219
200 // Returns true if the HTTP response code passed in corresponds to a 220 // Returns true if the HTTP response code passed in corresponds to a
201 // redirect. 221 // redirect.
202 static bool IsRedirectResponseCode(int response_code); 222 static bool IsRedirectResponseCode(int response_code);
203 223
204 // Returns true if the response cannot be reused without validation. The 224 // Returns VALIDATION_NONE if the response can be reused without
205 // result is relative to the current_time parameter, which is a parameter to 225 // validation. VALIDATION_ASYNCHRONOUS means the response can be re-used, but
206 // support unit testing. The request_time parameter indicates the time at 226 // asynchronous revalidation must be performed. VALIDATION_SYNCHRONOUS means
207 // which the request was made that resulted in this response, which was 227 // that the result cannot be reused without revalidation.
208 // received at response_time. 228 // The result is relative to the current_time parameter, which is
209 bool RequiresValidation(const base::Time& request_time, 229 // a parameter to support unit testing. The request_time parameter indicates
210 const base::Time& response_time, 230 // the time at which the request was made that resulted in this response,
211 const base::Time& current_time) const; 231 // which was received at response_time.
232 ValidationType RequiresValidation(const base::Time& request_time,
233 const base::Time& response_time,
234 const base::Time& current_time) const;
212 235
213 // Returns the amount of time the server claims the response is fresh from 236 // Calculates the amount of time the server claims the response is fresh from
214 // the time the response was generated. See section 13.2.4 of RFC 2616. See 237 // the time the response was generated. See section 13.2.4 of RFC 2616. See
215 // RequiresValidation for a description of the response_time parameter. 238 // RequiresValidation for a description of the response_time parameter. Sets
216 base::TimeDelta GetFreshnessLifetime(const base::Time& response_time) const; 239 // |Freshness.usable| to false and |Freshness.lifetime| to zero if there is a
rvargas (doing something else) 2014/09/11 02:33:07 Stale comment Maybe mention rfc 5861
Adam Rice 2014/09/12 01:46:49 Sorry about that. Updated.
240 // header that prohibits the use of the response. This allows us to
241 // distinguish cases when a stale response cannot be used by
242 // stale-while-revalidate.
243 FreshnessLifetimes GetFreshnessLifetimes(
244 const base::Time& response_time) const;
217 245
218 // Returns the age of the response. See section 13.2.3 of RFC 2616. 246 // Returns the age of the response. See section 13.2.3 of RFC 2616.
219 // See RequiresValidation for a description of this method's parameters. 247 // See RequiresValidation for a description of this method's parameters.
220 base::TimeDelta GetCurrentAge(const base::Time& request_time, 248 base::TimeDelta GetCurrentAge(const base::Time& request_time,
221 const base::Time& response_time, 249 const base::Time& response_time,
222 const base::Time& current_time) const; 250 const base::Time& current_time) const;
223 251
224 // The following methods extract values from the response headers. If a 252 // The following methods extract values from the response headers. If a
225 // value is not present, then false is returned. Otherwise, true is returned 253 // value is not present, then false is returned. Otherwise, true is returned
226 // and the out param is assigned to the corresponding value. 254 // and the out param is assigned to the corresponding value.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 416
389 // The parsed http version number (not normalized). 417 // The parsed http version number (not normalized).
390 HttpVersion parsed_http_version_; 418 HttpVersion parsed_http_version_;
391 419
392 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); 420 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders);
393 }; 421 };
394 422
395 } // namespace net 423 } // namespace net
396 424
397 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 425 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698