OLD | NEW |
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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 class Pickle; | 23 class Pickle; |
24 class PickleIterator; | 24 class PickleIterator; |
25 class Time; | 25 class Time; |
26 class TimeDelta; | 26 class TimeDelta; |
27 } | 27 } |
28 | 28 |
29 namespace net { | 29 namespace net { |
30 | 30 |
31 class HttpByteRange; | 31 class HttpByteRange; |
32 | 32 |
33 enum ValidationType { | |
34 VALIDATION_NONE, // The resource is fresh. | |
35 VALIDATION_ASYNCHRONOUS, // The resource requires async revalidation. | |
36 VALIDATION_SYNCHRONOUS // The resource requires sync revalidation. | |
37 }; | |
38 | |
39 // HttpResponseHeaders: parses and holds HTTP response headers. | 33 // HttpResponseHeaders: parses and holds HTTP response headers. |
40 class NET_EXPORT HttpResponseHeaders | 34 class NET_EXPORT HttpResponseHeaders |
41 : public base::RefCountedThreadSafe<HttpResponseHeaders> { | 35 : public base::RefCountedThreadSafe<HttpResponseHeaders> { |
42 public: | 36 public: |
43 // Persist options. | 37 // Persist options. |
44 typedef int PersistOptions; | 38 typedef int PersistOptions; |
45 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers. | 39 static const PersistOptions PERSIST_RAW = -1; // Raw, unparsed headers. |
46 static const PersistOptions PERSIST_ALL = 0; // Parsed headers. | 40 static const PersistOptions PERSIST_ALL = 0; // Parsed headers. |
47 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0; | 41 static const PersistOptions PERSIST_SANS_COOKIES = 1 << 0; |
48 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1; | 42 static const PersistOptions PERSIST_SANS_CHALLENGES = 1 << 1; |
49 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2; | 43 static const PersistOptions PERSIST_SANS_HOP_BY_HOP = 1 << 2; |
50 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3; | 44 static const PersistOptions PERSIST_SANS_NON_CACHEABLE = 1 << 3; |
51 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4; | 45 static const PersistOptions PERSIST_SANS_RANGES = 1 << 4; |
52 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5; | 46 static const PersistOptions PERSIST_SANS_SECURITY_STATE = 1 << 5; |
53 | 47 |
54 struct FreshnessLifetimes { | 48 struct ExpirationTimes { |
| 49 base::Time GetFreshnessExpiry() const { |
| 50 return corrected_response_time + freshness_lifetime; |
| 51 } |
| 52 |
| 53 base::Time GetStalenessExpiry() const { |
| 54 return corrected_response_time + staleness_lifetime; |
| 55 } |
| 56 |
| 57 // The |base::Time::Now()| value for which this request would have an age of |
| 58 // exactly zero. You can subtract this from |base::Time::Now()| to get the |
| 59 // current age. |
| 60 base::Time corrected_response_time; |
| 61 |
55 // How long the resource will be fresh for. | 62 // How long the resource will be fresh for. |
56 base::TimeDelta freshness; | 63 base::TimeDelta freshness_lifetime; |
| 64 |
57 // How long after becoming not fresh that the resource will be stale but | 65 // How long after becoming not fresh that the resource will be stale but |
58 // usable (if async revalidation is enabled). | 66 // usable (if async revalidation is enabled). |
59 base::TimeDelta staleness; | 67 base::TimeDelta staleness_lifetime; |
60 }; | 68 }; |
61 | 69 |
62 static const char kContentRange[]; | 70 static const char kContentRange[]; |
63 | 71 |
64 // Parses the given raw_headers. raw_headers should be formatted thus: | 72 // Parses the given raw_headers. raw_headers should be formatted thus: |
65 // includes the http status response line, each line is \0-terminated, and | 73 // includes the http status response line, each line is \0-terminated, and |
66 // it's terminated by an empty line (ie, 2 \0s in a row). | 74 // it's terminated by an empty line (ie, 2 \0s in a row). |
67 // (Note that line continuations should have already been joined; | 75 // (Note that line continuations should have already been joined; |
68 // see HttpUtil::AssembleRawHeaders) | 76 // see HttpUtil::AssembleRawHeaders) |
69 // | 77 // |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 bool GetCharset(std::string* charset) const; | 226 bool GetCharset(std::string* charset) const; |
219 | 227 |
220 // Returns true if this response corresponds to a redirect. The target | 228 // Returns true if this response corresponds to a redirect. The target |
221 // location of the redirect is optionally returned if location is non-null. | 229 // location of the redirect is optionally returned if location is non-null. |
222 bool IsRedirect(std::string* location) const; | 230 bool IsRedirect(std::string* location) const; |
223 | 231 |
224 // Returns true if the HTTP response code passed in corresponds to a | 232 // Returns true if the HTTP response code passed in corresponds to a |
225 // redirect. | 233 // redirect. |
226 static bool IsRedirectResponseCode(int response_code); | 234 static bool IsRedirectResponseCode(int response_code); |
227 | 235 |
228 // Returns VALIDATION_NONE if the response can be reused without | 236 // Returns an ExpirationTimes struct which can be used to calculate the |
229 // validation. VALIDATION_ASYNCHRONOUS means the response can be re-used, but | 237 // freshness and stale-white-revalidate status of this response. The values in |
230 // asynchronous revalidation must be performed. VALIDATION_SYNCHRONOUS means | 238 // the ExpirationTimes struct do not depend on the current time, so they can |
231 // that the result cannot be reused without revalidation. | 239 // be stored and used later as well. |
232 // The result is relative to the current_time parameter, which is | 240 ExpirationTimes GetExpirationTimes(const base::Time& request_time, |
233 // a parameter to support unit testing. The request_time parameter indicates | 241 const base::Time& response_time) const; |
234 // the time at which the request was made that resulted in this response, | |
235 // which was received at response_time. | |
236 ValidationType RequiresValidation(const base::Time& request_time, | |
237 const base::Time& response_time, | |
238 const base::Time& current_time) const; | |
239 | 242 |
240 // Calculates the amount of time the server claims the response is fresh from | 243 // Calculates the amount of time the server claims the response is fresh from |
241 // the time the response was generated. See section 13.2.4 of RFC 2616. See | 244 // the time the response was generated. See section 13.2.4 of RFC 2616. See |
242 // RequiresValidation for a description of the response_time parameter. See | 245 // RequiresValidation for a description of the response_time parameter. See |
243 // the definition of FreshnessLifetimes above for the meaning of the return | 246 // the definition of FreshnessLifetimes above for the meaning of the return |
244 // value. See RFC 5861 section 3 for the definition of | 247 // value. See RFC 5861 section 3 for the definition of |
245 // stale-while-revalidate. | 248 // stale-while-revalidate. |
246 FreshnessLifetimes GetFreshnessLifetimes( | 249 void CalculateLifetimes(const base::Time& response_time, |
247 const base::Time& response_time) const; | 250 base::TimeDelta* out_freshness_lifetime, |
248 | 251 base::TimeDelta* out_staleness_lifetime) const; |
249 // Returns the age of the response. See section 13.2.3 of RFC 2616. | |
250 // See RequiresValidation for a description of this method's parameters. | |
251 base::TimeDelta GetCurrentAge(const base::Time& request_time, | |
252 const base::Time& response_time, | |
253 const base::Time& current_time) const; | |
254 | 252 |
255 // The following methods extract values from the response headers. If a | 253 // The following methods extract values from the response headers. If a |
256 // value is not present, or is invalid, then false is returned. Otherwise, | 254 // value is not present, or is invalid, then false is returned. Otherwise, |
257 // true is returned and the out param is assigned to the corresponding value. | 255 // true is returned and the out param is assigned to the corresponding value. |
258 bool GetMaxAgeValue(base::TimeDelta* value) const; | 256 bool GetMaxAgeValue(base::TimeDelta* value) const; |
259 bool GetAgeValue(base::TimeDelta* value) const; | 257 bool GetAgeValue(base::TimeDelta* value) const; |
260 bool GetDateValue(base::Time* value) const; | 258 bool GetDateValue(base::Time* value) const; |
261 bool GetLastModifiedValue(base::Time* value) const; | 259 bool GetLastModifiedValue(base::Time* value) const; |
262 bool GetExpiresValue(base::Time* value) const; | 260 bool GetExpiresValue(base::Time* value) const; |
263 bool GetStaleWhileRevalidateValue(base::TimeDelta* value) const; | 261 bool GetStaleWhileRevalidateValue(base::TimeDelta* value) const; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 | 420 |
423 // The normalized http version (consistent with what GetStatusLine() returns). | 421 // The normalized http version (consistent with what GetStatusLine() returns). |
424 HttpVersion http_version_; | 422 HttpVersion http_version_; |
425 | 423 |
426 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); | 424 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); |
427 }; | 425 }; |
428 | 426 |
429 } // namespace net | 427 } // namespace net |
430 | 428 |
431 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ | 429 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ |
OLD | NEW |