| 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" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
| 18 #include "base/pickle.h" | 18 #include "base/pickle.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 24 #include "base/values.h" | 24 #include "base/values.h" |
| 25 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 26 #include "net/base/parse_number.h" |
| 26 #include "net/http/http_byte_range.h" | 27 #include "net/http/http_byte_range.h" |
| 27 #include "net/http/http_log_util.h" | 28 #include "net/http/http_log_util.h" |
| 28 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
| 29 | 30 |
| 30 using base::StringPiece; | 31 using base::StringPiece; |
| 31 using base::Time; | 32 using base::Time; |
| 32 using base::TimeDelta; | 33 using base::TimeDelta; |
| 33 | 34 |
| 34 namespace net { | 35 namespace net { |
| 35 | 36 |
| (...skipping 1112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 | 1149 |
| 1149 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { | 1150 bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { |
| 1150 return GetCacheControlDirective("max-age", result); | 1151 return GetCacheControlDirective("max-age", result); |
| 1151 } | 1152 } |
| 1152 | 1153 |
| 1153 bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const { | 1154 bool HttpResponseHeaders::GetAgeValue(TimeDelta* result) const { |
| 1154 std::string value; | 1155 std::string value; |
| 1155 if (!EnumerateHeader(nullptr, "Age", &value)) | 1156 if (!EnumerateHeader(nullptr, "Age", &value)) |
| 1156 return false; | 1157 return false; |
| 1157 | 1158 |
| 1158 int64_t seconds; | 1159 // Parse the delta-seconds as 1*DIGIT. |
| 1159 base::StringToInt64(value, &seconds); | 1160 uint32_t seconds; |
| 1161 ParseIntError error; |
| 1162 if (!ParseUint32(value, &seconds, &error)) { |
| 1163 if (error == ParseIntError::FAILED_OVERFLOW) { |
| 1164 // If the Age value cannot fit in a uint32_t, saturate it to a maximum |
| 1165 // value. This is similar to what RFC 2616 says in section 14.6 for how |
| 1166 // caches should transmit values that overflow. |
| 1167 seconds = std::numeric_limits<decltype(seconds)>::max(); |
| 1168 } else { |
| 1169 return false; |
| 1170 } |
| 1171 } |
| 1172 |
| 1160 *result = TimeDelta::FromSeconds(seconds); | 1173 *result = TimeDelta::FromSeconds(seconds); |
| 1161 return true; | 1174 return true; |
| 1162 } | 1175 } |
| 1163 | 1176 |
| 1164 bool HttpResponseHeaders::GetDateValue(Time* result) const { | 1177 bool HttpResponseHeaders::GetDateValue(Time* result) const { |
| 1165 return GetTimeValuedHeader("Date", result); | 1178 return GetTimeValuedHeader("Date", result); |
| 1166 } | 1179 } |
| 1167 | 1180 |
| 1168 bool HttpResponseHeaders::GetLastModifiedValue(Time* result) const { | 1181 bool HttpResponseHeaders::GetLastModifiedValue(Time* result) const { |
| 1169 return GetTimeValuedHeader("Last-Modified", result); | 1182 return GetTimeValuedHeader("Last-Modified", result); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 return true; | 1464 return true; |
| 1452 } | 1465 } |
| 1453 | 1466 |
| 1454 bool HttpResponseHeaders::IsChunkEncoded() const { | 1467 bool HttpResponseHeaders::IsChunkEncoded() const { |
| 1455 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1468 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
| 1456 return GetHttpVersion() >= HttpVersion(1, 1) && | 1469 return GetHttpVersion() >= HttpVersion(1, 1) && |
| 1457 HasHeaderValue("Transfer-Encoding", "chunked"); | 1470 HasHeaderValue("Transfer-Encoding", "chunked"); |
| 1458 } | 1471 } |
| 1459 | 1472 |
| 1460 } // namespace net | 1473 } // namespace net |
| OLD | NEW |