Chromium Code Reviews| 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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); | 1153 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); |
| 1154 } else { | 1154 } else { |
| 1155 // HTTP/1.1 responses default to keep-alive | 1155 // HTTP/1.1 responses default to keep-alive |
| 1156 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); | 1156 keep_alive = !LowerCaseEqualsASCII(connection_val, "close"); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 return keep_alive; | 1159 return keep_alive; |
| 1160 } | 1160 } |
| 1161 | 1161 |
| 1162 bool HttpResponseHeaders::HasStrongValidators() const { | 1162 bool HttpResponseHeaders::HasStrongValidators() const { |
| 1163 if (GetHttpVersion() < HttpVersion(1, 1)) | 1163 std::string etag_header; |
| 1164 return false; | 1164 EnumerateHeader(NULL, "etag", &etag_header); |
| 1165 | 1165 std::string last_modified_header; |
| 1166 std::string etag_value; | 1166 EnumerateHeader(NULL, "Last-Modified", &last_modified_header); |
|
scherkus (not reviewing)
2012/05/23 01:16:03
FYI I notice a lot of lower-case headers in this f
Ami GONE FROM CHROMIUM
2012/05/23 01:27:28
Elected to stay consistent with existing capitaliz
scherkus (not reviewing)
2012/05/23 01:34:19
Yeah nevermind -- the stuff at the top of this fil
| |
| 1167 EnumerateHeader(NULL, "etag", &etag_value); | 1167 std::string date_header; |
| 1168 if (!etag_value.empty()) { | 1168 EnumerateHeader(NULL, "Date", &last_modified_header); |
| 1169 size_t slash = etag_value.find('/'); | 1169 return HttpUtil::HasStrongValidators( |
| 1170 if (slash == std::string::npos || slash == 0) | 1170 GetHttpVersion(), etag_header, last_modified_header, date_header); |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: this call should start enumerating arguments
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
That'd require ASCII art and more vertical space t
rvargas (doing something else)
2012/05/23 18:26:09
Just look at the Google style guide.
| |
| 1171 return true; | |
| 1172 | |
| 1173 std::string::const_iterator i = etag_value.begin(); | |
| 1174 std::string::const_iterator j = etag_value.begin() + slash; | |
| 1175 HttpUtil::TrimLWS(&i, &j); | |
| 1176 if (!LowerCaseEqualsASCII(i, j, "w")) | |
| 1177 return true; | |
| 1178 } | |
| 1179 | |
| 1180 Time last_modified; | |
| 1181 if (!GetLastModifiedValue(&last_modified)) | |
| 1182 return false; | |
| 1183 | |
| 1184 Time date; | |
| 1185 if (!GetDateValue(&date)) | |
| 1186 return false; | |
| 1187 | |
| 1188 return ((date - last_modified).InSeconds() >= 60); | |
| 1189 } | 1171 } |
| 1190 | 1172 |
| 1191 // From RFC 2616: | 1173 // From RFC 2616: |
| 1192 // Content-Length = "Content-Length" ":" 1*DIGIT | 1174 // Content-Length = "Content-Length" ":" 1*DIGIT |
| 1193 int64 HttpResponseHeaders::GetContentLength() const { | 1175 int64 HttpResponseHeaders::GetContentLength() const { |
| 1194 void* iter = NULL; | 1176 void* iter = NULL; |
| 1195 std::string content_length_val; | 1177 std::string content_length_val; |
| 1196 if (!EnumerateHeader(&iter, "content-length", &content_length_val)) | 1178 if (!EnumerateHeader(&iter, "content-length", &content_length_val)) |
| 1197 return -1; | 1179 return -1; |
| 1198 | 1180 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1322 return true; | 1304 return true; |
| 1323 } | 1305 } |
| 1324 | 1306 |
| 1325 bool HttpResponseHeaders::IsChunkEncoded() const { | 1307 bool HttpResponseHeaders::IsChunkEncoded() const { |
| 1326 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. | 1308 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. |
| 1327 return GetHttpVersion() >= HttpVersion(1, 1) && | 1309 return GetHttpVersion() >= HttpVersion(1, 1) && |
| 1328 HasHeaderValue("Transfer-Encoding", "chunked"); | 1310 HasHeaderValue("Transfer-Encoding", "chunked"); |
| 1329 } | 1311 } |
| 1330 | 1312 |
| 1331 } // namespace net | 1313 } // namespace net |
| OLD | NEW |