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

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: Add load flag LOAD_ASYNC_REVALIDATION. 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 25 matching lines...) Expand all
36 typedef int PersistOptions; 36 typedef int PersistOptions;
37 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers. 37 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers.
38 static const PersistOptions PERSIST_ALL = 0; // Parsed headers. 38 static const PersistOptions PERSIST_ALL = 0; // Parsed headers.
39 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0; 39 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0;
40 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1; 40 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1;
41 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2; 41 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2;
42 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3; 42 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3;
43 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4; 43 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4;
44 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5; 44 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5;
45 45
46 enum ValidationType {
47 VALIDATION_NONE = 0, // the resource is fresh
48 VALIDATION_ASYNCHRONOUS, // the resource requires async revalidation
49 VALIDATION_SYNCHRONOUS // the resource requires sync revalidation
50 };
51
52 struct Freshness {
53 // Construct an "unusable" Freshness entry (lifetime = 0, usable = false)
54 Freshness();
55 // Construct a "usable" Freshness entry (lifetime >= 0, usable = true)
56 explicit Freshness(const base::TimeDelta& lifetime);
57 ~Freshness();
58
59 // True if the response might be usable (depending on freshness).
60 const bool usable;
61 // Invariant: if usable is false, lifetime is 0.
62 const base::TimeDelta lifetime;
63 };
64
46 static const char kContentRange[]; 65 static const char kContentRange[];
47 66
48 // Parses the given raw_headers. raw_headers should be formatted thus: 67 // Parses the given raw_headers. raw_headers should be formatted thus:
49 // includes the http status response line, each line is \0-terminated, and 68 // 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). 69 // it's terminated by an empty line (ie, 2 \0s in a row).
51 // (Note that line continuations should have already been joined; 70 // (Note that line continuations should have already been joined;
52 // see HttpUtil::AssembleRawHeaders) 71 // see HttpUtil::AssembleRawHeaders)
53 // 72 //
54 // HttpResponseHeaders does not perform any encoding changes on the input. 73 // HttpResponseHeaders does not perform any encoding changes on the input.
55 // 74 //
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool GetCharset(std::string* charset) const; 213 bool GetCharset(std::string* charset) const;
195 214
196 // Returns true if this response corresponds to a redirect. The target 215 // Returns true if this response corresponds to a redirect. The target
197 // location of the redirect is optionally returned if location is non-null. 216 // location of the redirect is optionally returned if location is non-null.
198 bool IsRedirect(std::string* location) const; 217 bool IsRedirect(std::string* location) const;
199 218
200 // Returns true if the HTTP response code passed in corresponds to a 219 // Returns true if the HTTP response code passed in corresponds to a
201 // redirect. 220 // redirect.
202 static bool IsRedirectResponseCode(int response_code); 221 static bool IsRedirectResponseCode(int response_code);
203 222
204 // Returns true if the response cannot be reused without validation. The 223 // Returns VALIDATION_NONE if the response can be reused without
205 // result is relative to the current_time parameter, which is a parameter to 224 // validation. VALIDATION_ASYNCHRONOUS means the response can be re-used, but
206 // support unit testing. The request_time parameter indicates the time at 225 // asynchronous revalidation must be performed. VALIDATION_SYNCHRONOUS means
207 // which the request was made that resulted in this response, which was 226 // that the result cannot be reused without revalidation.
208 // received at response_time. 227 // The result is relative to the current_time parameter, which is
209 bool RequiresValidation(const base::Time& request_time, 228 // a parameter to support unit testing. The request_time parameter indicates
210 const base::Time& response_time, 229 // the time at which the request was made that resulted in this response,
211 const base::Time& current_time) const; 230 // which was received at response_time.
231 ValidationType RequiresValidation(const base::Time& request_time,
232 const base::Time& response_time,
233 const base::Time& current_time) const;
212 234
213 // Returns the amount of time the server claims the response is fresh from 235 // 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 236 // 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. 237 // RequiresValidation for a description of the response_time parameter. Sets
216 base::TimeDelta GetFreshnessLifetime(const base::Time& response_time) const; 238 // |Freshness.usable| to false and |Freshness.lifetime| to zero if there is a
239 // header that prohibits the use of the response. This allows us to
240 // distinguish cases when a stale response cannot be used by
241 // stale-while-revalidate.
242 Freshness GetFreshnessLifetime(const base::Time& response_time) const;
217 243
218 // Returns the age of the response. See section 13.2.3 of RFC 2616. 244 // 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. 245 // See RequiresValidation for a description of this method's parameters.
220 base::TimeDelta GetCurrentAge(const base::Time& request_time, 246 base::TimeDelta GetCurrentAge(const base::Time& request_time,
221 const base::Time& response_time, 247 const base::Time& response_time,
222 const base::Time& current_time) const; 248 const base::Time& current_time) const;
223 249
224 // The following methods extract values from the response headers. If a 250 // The following methods extract values from the response headers. If a
225 // value is not present, then false is returned. Otherwise, true is returned 251 // value is not present, then false is returned. Otherwise, true is returned
226 // and the out param is assigned to the corresponding value. 252 // and the out param is assigned to the corresponding value.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 414
389 // The parsed http version number (not normalized). 415 // The parsed http version number (not normalized).
390 HttpVersion parsed_http_version_; 416 HttpVersion parsed_http_version_;
391 417
392 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); 418 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders);
393 }; 419 };
394 420
395 } // namespace net 421 } // namespace net
396 422
397 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 423 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698