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

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

Issue 154243006: Add GetExpirationTimes() to HttpResponseHeader. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move a function body Created 4 years, 7 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 | Annotate | Revision Log
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 12 matching lines...) Expand all
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 // The time after which the resource must be validated.
50 base::Time GetExpirationTime() const {
mmenke 2016/04/29 16:15:53 expiration_time()?
Randy Smith (Not in Mondays) 2016/05/04 19:22:15 I find it confusing (found it confusing in one of
51 return corrected_response_time + freshness_lifetime;
52 }
53
54 // The time after which the resource must be validated synchronously.
55 base::Time GetAsyncExpirationTime() const {
mmenke 2016/04/29 16:15:54 I think this comment needs to be clearer. What do
mmenke 2016/04/29 16:15:54 async_expiration_time()?
56 return corrected_response_time + staleness_lifetime;
57 }
58
Randy Smith (Not in Mondays) 2016/05/04 19:22:15 Why can't the rest of this structure be private?
59 // The |base::Time::Now()| value for which this request would have an age of
60 // exactly zero. You can subtract this from |base::Time::Now()| to get the
61 // current age.
62 base::Time corrected_response_time;
63
55 // How long the resource will be fresh for. 64 // How long the resource will be fresh for.
Randy Smith (Not in Mondays) 2016/05/04 19:22:16 nit: Given that this is a time delta, wouldn't it
56 base::TimeDelta freshness; 65 base::TimeDelta freshness_lifetime;
mmenke 2016/04/29 16:15:53 I think the names of related functions / values sh
66
57 // How long after becoming not fresh that the resource will be stale but 67 // How long after becoming not fresh that the resource will be stale but
58 // usable (if async revalidation is enabled). 68 // usable (if async revalidation is enabled).
mmenke 2016/04/29 16:15:54 This comment is wrong. This implies that GetAsync
Randy Smith (Not in Mondays) 2016/05/04 19:22:15 +1 (mostly as a reminder to myself to come back an
59 base::TimeDelta staleness; 69 base::TimeDelta staleness_lifetime;
60 }; 70 };
61 71
62 static const char kContentRange[]; 72 static const char kContentRange[];
63 73
64 // Parses the given raw_headers. raw_headers should be formatted thus: 74 // Parses the given raw_headers. raw_headers should be formatted thus:
65 // includes the http status response line, each line is \0-terminated, and 75 // 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). 76 // it's terminated by an empty line (ie, 2 \0s in a row).
67 // (Note that line continuations should have already been joined; 77 // (Note that line continuations should have already been joined;
68 // see HttpUtil::AssembleRawHeaders) 78 // see HttpUtil::AssembleRawHeaders)
69 // 79 //
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 bool GetCharset(std::string* charset) const; 228 bool GetCharset(std::string* charset) const;
219 229
220 // Returns true if this response corresponds to a redirect. The target 230 // Returns true if this response corresponds to a redirect. The target
221 // location of the redirect is optionally returned if location is non-null. 231 // location of the redirect is optionally returned if location is non-null.
222 bool IsRedirect(std::string* location) const; 232 bool IsRedirect(std::string* location) const;
223 233
224 // Returns true if the HTTP response code passed in corresponds to a 234 // Returns true if the HTTP response code passed in corresponds to a
225 // redirect. 235 // redirect.
226 static bool IsRedirectResponseCode(int response_code); 236 static bool IsRedirectResponseCode(int response_code);
227 237
228 // Returns VALIDATION_NONE if the response can be reused without 238 // Returns an ExpirationTimes struct which can be used to calculate the
229 // validation. VALIDATION_ASYNCHRONOUS means the response can be re-used, but 239 // freshness and stale-white-revalidate status of this response. The values in
230 // asynchronous revalidation must be performed. VALIDATION_SYNCHRONOUS means 240 // the ExpirationTimes struct do not depend on the current time, so they can
231 // that the result cannot be reused without revalidation. 241 // be stored and used later as well.
232 // The result is relative to the current_time parameter, which is 242 ExpirationTimes GetExpirationTimes(const base::Time& request_time,
233 // a parameter to support unit testing. The request_time parameter indicates 243 const base::Time& response_time) const;
mmenke 2016/04/29 16:15:53 const base::Time& -> base::Time
mmenke 2016/04/29 16:15:54 A bit unrelated to this CL, but I've always wonder
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
240 // 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
242 // RequiresValidation for a description of the response_time parameter. See
243 // the definition of FreshnessLifetimes above for the meaning of the return
244 // value. See RFC 5861 section 3 for the definition of
245 // stale-while-revalidate.
246 FreshnessLifetimes GetFreshnessLifetimes(
247 const base::Time& response_time) const;
248
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 244
255 // The following methods extract values from the response headers. If a 245 // The following methods extract values from the response headers. If a
256 // value is not present, or is invalid, then false is returned. Otherwise, 246 // 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. 247 // true is returned and the out param is assigned to the corresponding value.
258 bool GetMaxAgeValue(base::TimeDelta* value) const; 248 bool GetMaxAgeValue(base::TimeDelta* value) const;
259 bool GetAgeValue(base::TimeDelta* value) const; 249 bool GetAgeValue(base::TimeDelta* value) const;
260 bool GetDateValue(base::Time* value) const; 250 bool GetDateValue(base::Time* value) const;
261 bool GetLastModifiedValue(base::Time* value) const; 251 bool GetLastModifiedValue(base::Time* value) const;
262 bool GetExpiresValue(base::Time* value) const; 252 bool GetExpiresValue(base::Time* value) const;
263 bool GetStaleWhileRevalidateValue(base::TimeDelta* value) const; 253 bool GetStaleWhileRevalidateValue(base::TimeDelta* value) const;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Find the header in our list (case-insensitive) starting with parsed_ at 347 // Find the header in our list (case-insensitive) starting with parsed_ at
358 // index |from|. Returns string::npos if not found. 348 // index |from|. Returns string::npos if not found.
359 size_t FindHeader(size_t from, const base::StringPiece& name) const; 349 size_t FindHeader(size_t from, const base::StringPiece& name) const;
360 350
361 // Search the Cache-Control header for a directive matching |directive|. If 351 // Search the Cache-Control header for a directive matching |directive|. If
362 // present, treat its value as a time offset in seconds, write it to |result|, 352 // present, treat its value as a time offset in seconds, write it to |result|,
363 // and return true. 353 // and return true.
364 bool GetCacheControlDirective(const base::StringPiece& directive, 354 bool GetCacheControlDirective(const base::StringPiece& directive,
365 base::TimeDelta* result) const; 355 base::TimeDelta* result) const;
366 356
357 // Calculates the amount of time the server claims the response is fresh from
358 // the time the response was generated. See section 13.2.4 of RFC 2616. See
359 // RequiresValidation for a description of the response_time parameter. See
360 // the definition of FreshnessLifetimes above for the meaning of the return
Randy Smith (Not in Mondays) 2016/05/04 19:22:15 I don't believe that RequiresValidation() or Fresh
361 // value. See RFC 5861 section 3 for the definition of stale-while-revalidate.
362 void CalculateLifetimes(const base::Time& response_time,
363 base::TimeDelta* out_freshness_lifetime,
364 base::TimeDelta* out_staleness_lifetime) const;
365
367 // Add a header->value pair to our list. If we already have header in our 366 // Add a header->value pair to our list. If we already have header in our
368 // list, append the value to it. 367 // list, append the value to it.
369 void AddHeader(std::string::const_iterator name_begin, 368 void AddHeader(std::string::const_iterator name_begin,
370 std::string::const_iterator name_end, 369 std::string::const_iterator name_end,
371 std::string::const_iterator value_begin, 370 std::string::const_iterator value_begin,
372 std::string::const_iterator value_end); 371 std::string::const_iterator value_end);
373 372
374 // Add to parsed_ given the fields of a ParsedHeader object. 373 // Add to parsed_ given the fields of a ParsedHeader object.
375 void AddToParsed(std::string::const_iterator name_begin, 374 void AddToParsed(std::string::const_iterator name_begin,
376 std::string::const_iterator name_end, 375 std::string::const_iterator name_end,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 421
423 // The normalized http version (consistent with what GetStatusLine() returns). 422 // The normalized http version (consistent with what GetStatusLine() returns).
424 HttpVersion http_version_; 423 HttpVersion http_version_;
425 424
426 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders); 425 DISALLOW_COPY_AND_ASSIGN(HttpResponseHeaders);
427 }; 426 };
428 427
429 } // namespace net 428 } // namespace net
430 429
431 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_ 430 #endif // NET_HTTP_HTTP_RESPONSE_HEADERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698