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

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: Compile fix for ResourcePrefreshPredictor. Created 6 years, 2 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.
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 // How long the resource will be fresh for.
54 base::TimeDelta fresh;
55 // How long after becoming not fresh that the resource will be stale but
56 // usable (if async revalidation is enabled).
57 base::TimeDelta stale;
58 };
59
46 static const char kContentRange[]; 60 static const char kContentRange[];
47 61
48 // Parses the given raw_headers. raw_headers should be formatted thus: 62 // Parses the given raw_headers. raw_headers should be formatted thus:
49 // includes the http status response line, each line is \0-terminated, and 63 // 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). 64 // it's terminated by an empty line (ie, 2 \0s in a row).
51 // (Note that line continuations should have already been joined; 65 // (Note that line continuations should have already been joined;
52 // see HttpUtil::AssembleRawHeaders) 66 // see HttpUtil::AssembleRawHeaders)
53 // 67 //
54 // HttpResponseHeaders does not perform any encoding changes on the input. 68 // HttpResponseHeaders does not perform any encoding changes on the input.
55 // 69 //
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool GetCharset(std::string* charset) const; 208 bool GetCharset(std::string* charset) const;
195 209
196 // Returns true if this response corresponds to a redirect. The target 210 // Returns true if this response corresponds to a redirect. The target
197 // location of the redirect is optionally returned if location is non-null. 211 // location of the redirect is optionally returned if location is non-null.
198 bool IsRedirect(std::string* location) const; 212 bool IsRedirect(std::string* location) const;
199 213
200 // Returns true if the HTTP response code passed in corresponds to a 214 // Returns true if the HTTP response code passed in corresponds to a
201 // redirect. 215 // redirect.
202 static bool IsRedirectResponseCode(int response_code); 216 static bool IsRedirectResponseCode(int response_code);
203 217
204 // Returns true if the response cannot be reused without validation. The 218 // Returns VALIDATION_NONE if the response can be reused without
205 // result is relative to the current_time parameter, which is a parameter to 219 // validation. VALIDATION_ASYNCHRONOUS means the response can be re-used, but
206 // support unit testing. The request_time parameter indicates the time at 220 // asynchronous revalidation must be performed. VALIDATION_SYNCHRONOUS means
207 // which the request was made that resulted in this response, which was 221 // that the result cannot be reused without revalidation.
208 // received at response_time. 222 // The result is relative to the current_time parameter, which is
209 bool RequiresValidation(const base::Time& request_time, 223 // a parameter to support unit testing. The request_time parameter indicates
210 const base::Time& response_time, 224 // the time at which the request was made that resulted in this response,
211 const base::Time& current_time) const; 225 // which was received at response_time.
226 ValidationType RequiresValidation(const base::Time& request_time,
227 const base::Time& response_time,
228 const base::Time& current_time) const;
212 229
213 // Returns the amount of time the server claims the response is fresh from 230 // 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 231 // 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. 232 // RequiresValidation for a description of the response_time parameter. Sets
216 base::TimeDelta GetFreshnessLifetime(const base::Time& response_time) const; 233 // |FreshnessLifetimes.fresh| to the length of time the response may be used
234 // without revalidation, and |FreshnessLifetimes.stale| to the length of time
235 // the response may be used stale with asynchronous revalidation if
236 // stale-while-revalidate support is enabled. See RFC 5861 section 3 for the
237 // definition of stale-while-revalidate.
238 FreshnessLifetimes GetFreshnessLifetimes(
239 const base::Time& response_time) const;
217 240
218 // Returns the age of the response. See section 13.2.3 of RFC 2616. 241 // 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. 242 // See RequiresValidation for a description of this method's parameters.
220 base::TimeDelta GetCurrentAge(const base::Time& request_time, 243 base::TimeDelta GetCurrentAge(const base::Time& request_time,
221 const base::Time& response_time, 244 const base::Time& response_time,
222 const base::Time& current_time) const; 245 const base::Time& current_time) const;
223 246
224 // The following methods extract values from the response headers. If a 247 // The following methods extract values from the response headers. If a
225 // value is not present, then false is returned. Otherwise, true is returned 248 // value is not present, then false is returned. Otherwise, true is returned
226 // and the out param is assigned to the corresponding value. 249 // and the out param is assigned to the corresponding value.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 411
389 // The parsed http version number (not normalized). 412 // The parsed http version number (not normalized).
390 HttpVersion parsed_http_version_; 413 HttpVersion parsed_http_version_;
391 414
392 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); 415 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders);
393 }; 416 };
394 417
395 } // namespace net 418 } // namespace net
396 419
397 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 420 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698