OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 // HTTP/1.0 responses default to NOT keep-alive | 994 // HTTP/1.0 responses default to NOT keep-alive |
995 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); | 995 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); |
996 } else { | 996 } else { |
997 // HTTP/1.1 responses default to keep-alive | 997 // HTTP/1.1 responses default to keep-alive |
998 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); | 998 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); |
999 } | 999 } |
1000 | 1000 |
1001 return keep_alive; | 1001 return keep_alive; |
1002 } | 1002 } |
1003 | 1003 |
| 1004 bool HttpResponseHeaders::HasStrongValidators() const { |
| 1005 std::string etag_value; |
| 1006 EnumerateHeader(NULL, "etag", &etag_value); |
| 1007 if (!etag_value.empty()) { |
| 1008 size_t slash = etag_value.find('/'); |
| 1009 if (slash == std::string::npos || slash == 0) |
| 1010 return true; |
| 1011 |
| 1012 std::string::const_iterator i = etag_value.begin(); |
| 1013 std::string::const_iterator j = etag_value.begin() + slash; |
| 1014 HttpUtil::TrimLWS(&i, &j); |
| 1015 if (!LowerCaseEqualsASCII(i, j, "w")) |
| 1016 return true; |
| 1017 } |
| 1018 |
| 1019 Time last_modified; |
| 1020 if (!GetLastModifiedValue(&last_modified)) |
| 1021 return false; |
| 1022 |
| 1023 Time date; |
| 1024 if (!GetDateValue(&date)) |
| 1025 return false; |
| 1026 |
| 1027 return ((date - last_modified).InSeconds() >= 60); |
| 1028 } |
| 1029 |
1004 // From RFC 2616: | 1030 // From RFC 2616: |
1005 // Content-Length = "Content-Length" ":" 1*DIGIT | 1031 // Content-Length = "Content-Length" ":" 1*DIGIT |
1006 int64 HttpResponseHeaders::GetContentLength() const { | 1032 int64 HttpResponseHeaders::GetContentLength() const { |
1007 void* iter = NULL; | 1033 void* iter = NULL; |
1008 std::string content_length_val; | 1034 std::string content_length_val; |
1009 if (!EnumerateHeader(&iter, "content-length", &content_length_val)) | 1035 if (!EnumerateHeader(&iter, "content-length", &content_length_val)) |
1010 return -1; | 1036 return -1; |
1011 | 1037 |
1012 if (content_length_val.empty()) | 1038 if (content_length_val.empty()) |
1013 return -1; | 1039 return -1; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 // We have all the values; let's verify that they make sense for a 206 | 1155 // We have all the values; let's verify that they make sense for a 206 |
1130 // response. | 1156 // response. |
1131 if (*first_byte_position < 0 || *last_byte_position < 0 || | 1157 if (*first_byte_position < 0 || *last_byte_position < 0 || |
1132 *instance_length < 0 || *instance_length - 1 < *last_byte_position) | 1158 *instance_length < 0 || *instance_length - 1 < *last_byte_position) |
1133 return false; | 1159 return false; |
1134 | 1160 |
1135 return true; | 1161 return true; |
1136 } | 1162 } |
1137 | 1163 |
1138 } // namespace net | 1164 } // namespace net |
OLD | NEW |