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

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

Issue 670303003: Use DCHECK_EQ() when comparing TimeDeltas. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s-w-r-mmenke-fixes
Patch Set: Merge latest changes. Created 6 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The rules for header parsing were borrowed from Firefox: 5 // The rules for header parsing were borrowed from Firefox:
6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp 6 // http://lxr.mozilla.org/seamonkey/source/netwerk/protocol/http/src/nsHttpRespo nseHead.cpp
7 // The rules for parsing content-types were also borrowed from Firefox: 7 // The rules for parsing content-types were also borrowed from Firefox:
8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834 8 // http://lxr.mozilla.org/mozilla/source/netwerk/base/src/nsURLHelper.cpp#834
9 9
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 1003 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 HasHeaderValue("pragma", "no-cache") || 1014 HasHeaderValue("pragma", "no-cache") ||
1015 // Vary: * is never usable: see RFC 2616 section 13.6. 1015 // Vary: * is never usable: see RFC 2616 section 13.6.
1016 HasHeaderValue("vary", "*")) { 1016 HasHeaderValue("vary", "*")) {
1017 return lifetimes; 1017 return lifetimes;
1018 } 1018 }
1019 1019
1020 // Cache-Control directive must_revalidate overrides stale-while-revalidate. 1020 // Cache-Control directive must_revalidate overrides stale-while-revalidate.
1021 bool must_revalidate = HasHeaderValue("cache-control", "must-revalidate"); 1021 bool must_revalidate = HasHeaderValue("cache-control", "must-revalidate");
1022 1022
1023 if (must_revalidate || !GetStaleWhileRevalidateValue(&lifetimes.staleness)) { 1023 if (must_revalidate || !GetStaleWhileRevalidateValue(&lifetimes.staleness)) {
1024 DCHECK(lifetimes.staleness == TimeDelta()); 1024 DCHECK_EQ(TimeDelta(), lifetimes.staleness);
1025 } 1025 }
1026 1026
1027 // NOTE: "Cache-Control: max-age" overrides Expires, so we only check the 1027 // NOTE: "Cache-Control: max-age" overrides Expires, so we only check the
1028 // Expires header after checking for max-age in GetFreshnessLifetimes. This 1028 // Expires header after checking for max-age in GetFreshnessLifetimes. This
1029 // is important since "Expires: <date in the past>" means not fresh, but 1029 // is important since "Expires: <date in the past>" means not fresh, but
1030 // it should not trump a max-age value. 1030 // it should not trump a max-age value.
1031 if (GetMaxAgeValue(&lifetimes.freshness)) 1031 if (GetMaxAgeValue(&lifetimes.freshness))
1032 return lifetimes; 1032 return lifetimes;
1033 1033
1034 // If there is no Date header, then assume that the server response was 1034 // If there is no Date header, then assume that the server response was
1035 // generated at the time when we received the response. 1035 // generated at the time when we received the response.
1036 Time date_value; 1036 Time date_value;
1037 if (!GetDateValue(&date_value)) 1037 if (!GetDateValue(&date_value))
1038 date_value = response_time; 1038 date_value = response_time;
1039 1039
1040 Time expires_value; 1040 Time expires_value;
1041 if (GetExpiresValue(&expires_value)) { 1041 if (GetExpiresValue(&expires_value)) {
1042 // The expires value can be a date in the past! 1042 // The expires value can be a date in the past!
1043 if (expires_value > date_value) { 1043 if (expires_value > date_value) {
1044 lifetimes.freshness = expires_value - date_value; 1044 lifetimes.freshness = expires_value - date_value;
1045 return lifetimes; 1045 return lifetimes;
1046 } 1046 }
1047 1047
1048 DCHECK(lifetimes.freshness == TimeDelta()); 1048 DCHECK_EQ(TimeDelta(), lifetimes.freshness);
1049 return lifetimes; 1049 return lifetimes;
1050 } 1050 }
1051 1051
1052 // From RFC 2616 section 13.4: 1052 // From RFC 2616 section 13.4:
1053 // 1053 //
1054 // A response received with a status code of 200, 203, 206, 300, 301 or 410 1054 // A response received with a status code of 200, 203, 206, 300, 301 or 410
1055 // MAY be stored by a cache and used in reply to a subsequent request, 1055 // MAY be stored by a cache and used in reply to a subsequent request,
1056 // subject to the expiration mechanism, unless a cache-control directive 1056 // subject to the expiration mechanism, unless a cache-control directive
1057 // prohibits caching. 1057 // prohibits caching.
1058 // ... 1058 // ...
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 || 1090 if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 ||
1091 response_code_ == 410) { 1091 response_code_ == 410) {
1092 lifetimes.freshness = TimeDelta::Max(); 1092 lifetimes.freshness = TimeDelta::Max();
1093 lifetimes.staleness = TimeDelta(); // It should never be stale. 1093 lifetimes.staleness = TimeDelta(); // It should never be stale.
1094 return lifetimes; 1094 return lifetimes;
1095 } 1095 }
1096 1096
1097 // Our heuristic freshness estimate for this resource is 0 seconds, in 1097 // Our heuristic freshness estimate for this resource is 0 seconds, in
1098 // accordance with common browser behaviour. However, stale-while-revalidate 1098 // accordance with common browser behaviour. However, stale-while-revalidate
1099 // may still apply. 1099 // may still apply.
1100 DCHECK(lifetimes.freshness == TimeDelta()); 1100 DCHECK_EQ(TimeDelta(), lifetimes.freshness);
1101 return lifetimes; 1101 return lifetimes;
1102 } 1102 }
1103 1103
1104 // From RFC 2616 section 13.2.3: 1104 // From RFC 2616 section 13.2.3:
1105 // 1105 //
1106 // Summary of age calculation algorithm, when a cache receives a response: 1106 // Summary of age calculation algorithm, when a cache receives a response:
1107 // 1107 //
1108 // /* 1108 // /*
1109 // * age_value 1109 // * age_value
1110 // * is the value of Age: header received by the cache with 1110 // * is the value of Age: header received by the cache with
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 return true; 1443 return true;
1444 } 1444 }
1445 1445
1446 bool HttpResponseHeaders::IsChunkEncoded() const { 1446 bool HttpResponseHeaders::IsChunkEncoded() const {
1447 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1447 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1448 return GetHttpVersion() >= HttpVersion(1, 1) && 1448 return GetHttpVersion() >= HttpVersion(1, 1) &&
1449 HasHeaderValue("Transfer-Encoding", "chunked"); 1449 HasHeaderValue("Transfer-Encoding", "chunked");
1450 } 1450 }
1451 1451
1452 } // namespace net 1452 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698