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 // 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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 return true; | 915 return true; |
916 } | 916 } |
917 | 917 |
918 // static | 918 // static |
919 bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { | 919 bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
920 // Users probably want to see 300 (multiple choice) pages, so we don't count | 920 // Users probably want to see 300 (multiple choice) pages, so we don't count |
921 // them as redirects that need to be followed. | 921 // them as redirects that need to be followed. |
922 return (response_code == 301 || | 922 return (response_code == 301 || |
923 response_code == 302 || | 923 response_code == 302 || |
924 response_code == 303 || | 924 response_code == 303 || |
925 response_code == 307); | 925 response_code == 307 || |
926 response_code == 308); | |
926 } | 927 } |
927 | 928 |
928 // From RFC 2616 section 13.2.4: | 929 // From RFC 2616 section 13.2.4: |
929 // | 930 // |
930 // The calculation to determine if a response has expired is quite simple: | 931 // The calculation to determine if a response has expired is quite simple: |
931 // | 932 // |
932 // response_is_fresh = (freshness_lifetime > current_age) | 933 // response_is_fresh = (freshness_lifetime > current_age) |
933 // | 934 // |
934 // Of course, there are other factors that can force a response to always be | 935 // Of course, there are other factors that can force a response to always be |
935 // validated or re-fetched. | 936 // validated or re-fetched. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 // | 1015 // |
1015 // From RFC 2616 section 14.9.4: | 1016 // From RFC 2616 section 14.9.4: |
1016 // | 1017 // |
1017 // When the must-revalidate directive is present in a response received by | 1018 // When the must-revalidate directive is present in a response received by |
1018 // a cache, that cache MUST NOT use the entry after it becomes stale to | 1019 // a cache, that cache MUST NOT use the entry after it becomes stale to |
1019 // respond to a subsequent request without first revalidating it with the | 1020 // respond to a subsequent request without first revalidating it with the |
1020 // origin server. (I.e., the cache MUST do an end-to-end revalidation every | 1021 // origin server. (I.e., the cache MUST do an end-to-end revalidation every |
1021 // time, if, based solely on the origin server's Expires or max-age value, | 1022 // time, if, based solely on the origin server's Expires or max-age value, |
1022 // the cached response is stale.) | 1023 // the cached response is stale.) |
1023 // | 1024 // |
1025 // https://datatracker.ietf.org/doc/draft-reschke-http-status-308/ is an | |
1026 // experimental RFC that adds 308 permanent redirect as well, for which "any | |
1027 // future references ... SHOULD use one of the returned URIs." | |
mmenke
2014/04/23 15:45:29
Is there a non-expired doc I should be pointing to
| |
1024 if ((response_code_ == 200 || response_code_ == 203 || | 1028 if ((response_code_ == 200 || response_code_ == 203 || |
1025 response_code_ == 206) && | 1029 response_code_ == 206) && |
1026 !HasHeaderValue("cache-control", "must-revalidate")) { | 1030 !HasHeaderValue("cache-control", "must-revalidate")) { |
1027 // TODO(darin): Implement a smarter heuristic. | 1031 // TODO(darin): Implement a smarter heuristic. |
1028 Time last_modified_value; | 1032 Time last_modified_value; |
1029 if (GetLastModifiedValue(&last_modified_value)) { | 1033 if (GetLastModifiedValue(&last_modified_value)) { |
1030 // The last-modified value can be a date in the past! | 1034 // The last-modified value can be a date in the past! |
1031 if (last_modified_value <= date_value) | 1035 if (last_modified_value <= date_value) |
1032 return (date_value - last_modified_value) / 10; | 1036 return (date_value - last_modified_value) / 10; |
1033 } | 1037 } |
1034 } | 1038 } |
1035 | 1039 |
1036 // These responses are implicitly fresh (unless otherwise overruled): | 1040 // These responses are implicitly fresh (unless otherwise overruled): |
1037 if (response_code_ == 300 || response_code_ == 301 || response_code_ == 410) | 1041 if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 || |
1042 response_code_ == 410) { | |
1038 return TimeDelta::Max(); | 1043 return TimeDelta::Max(); |
1044 } | |
1039 | 1045 |
1040 return TimeDelta(); // not fresh | 1046 return TimeDelta(); // not fresh |
1041 } | 1047 } |
1042 | 1048 |
1043 // From RFC 2616 section 13.2.3: | 1049 // From RFC 2616 section 13.2.3: |
1044 // | 1050 // |
1045 // Summary of age calculation algorithm, when a cache receives a response: | 1051 // Summary of age calculation algorithm, when a cache receives a response: |
1046 // | 1052 // |
1047 // /* | 1053 // /* |
1048 // * age_value | 1054 // * age_value |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1497 // should not generate representation metadata other than Cache-Control, | 1503 // should not generate representation metadata other than Cache-Control, |
1498 // Content-Location, Date, ETag, Expires, and Vary. | 1504 // Content-Location, Date, ETag, Expires, and Vary. |
1499 return ProxyService::MISSING_VIA_HEADER; | 1505 return ProxyService::MISSING_VIA_HEADER; |
1500 } | 1506 } |
1501 // There is no bypass event. | 1507 // There is no bypass event. |
1502 return ProxyService::BYPASS_EVENT_TYPE_MAX; | 1508 return ProxyService::BYPASS_EVENT_TYPE_MAX; |
1503 } | 1509 } |
1504 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1510 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
1505 | 1511 |
1506 } // namespace net | 1512 } // namespace net |
OLD | NEW |