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

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

Issue 640213002: Make HRH::IsKeepAlive() look past the first header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments and Proxy-Connection tests. Created 6 years, 2 months 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 | net/http/http_response_headers_unittest.cc » ('j') | 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 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 // (crbug.com/135131) this better matches our cookie expiration 1162 // (crbug.com/135131) this better matches our cookie expiration
1163 // time parser which ignores timezone specifiers and assumes GMT. 1163 // time parser which ignores timezone specifiers and assumes GMT.
1164 // 4. This is exactly what Firefox does. 1164 // 4. This is exactly what Firefox does.
1165 // TODO(pauljensen): The ideal solution would be to return false if the 1165 // TODO(pauljensen): The ideal solution would be to return false if the
1166 // timezone could not be understood so as to avoid makeing other calculations 1166 // timezone could not be understood so as to avoid makeing other calculations
1167 // based on an incorrect time. This would require modifying the time 1167 // based on an incorrect time. This would require modifying the time
1168 // library or duplicating the code. (http://crbug.com/158327) 1168 // library or duplicating the code. (http://crbug.com/158327)
1169 return Time::FromUTCString(value.c_str(), result); 1169 return Time::FromUTCString(value.c_str(), result);
1170 } 1170 }
1171 1171
1172 // We accept the first value of "close" or "keep-alive" in a Connection or
1173 // Proxy-Connection header, in that order. Obeying "keep-alive" in HTTP/1.1 or
1174 // "close" in 1.0 is not strictly standards-compliant, but we'd like to
1175 // avoid looking at the Proxy-Connection header whenever it is reasonable to do
1176 // so.
1177 // TODO(ricea): Measure real-world usage of the "Proxy-Connection" header,
1178 // with a view to reducing support for it in order to make our Connection header
1179 // handling more RFC 7230 compliant.
1172 bool HttpResponseHeaders::IsKeepAlive() const { 1180 bool HttpResponseHeaders::IsKeepAlive() const {
1181 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is
1182 // meaningful when we don't know that this response was from a proxy, but
1183 // Mozilla also does this, so we'll do the same.
1184 static const char* kConnectionHeaders[] = {"connection", "proxy-connection"};
1185 struct KeepAliveToken {
1186 const char* token;
1187 bool keep_alive;
1188 };
1189 static const KeepAliveToken kKeepAliveTokens[] = {{"keep-alive", true},
1190 {"close", false}};
1191
1173 if (http_version_ < HttpVersion(1, 0)) 1192 if (http_version_ < HttpVersion(1, 0))
1174 return false; 1193 return false;
1175 1194
1176 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is 1195 for (const char* header : kConnectionHeaders) {
1177 // meaningful when we don't know that this response was from a proxy, but 1196 void* iterator = nullptr;
1178 // Mozilla also does this, so we'll do the same. 1197 std::string token;
1179 std::string connection_val; 1198 while (EnumerateHeader(&iterator, header, &token)) {
1180 if (!EnumerateHeader(NULL, "connection", &connection_val)) 1199 for (const KeepAliveToken& keep_alive_token : kKeepAliveTokens) {
1181 EnumerateHeader(NULL, "proxy-connection", &connection_val); 1200 if (LowerCaseEqualsASCII(token, keep_alive_token.token))
1182 1201 return keep_alive_token.keep_alive;
1183 bool keep_alive; 1202 }
1184 1203 }
1185 if (http_version_ == HttpVersion(1, 0)) {
1186 // HTTP/1.0 responses default to NOT keep-alive
1187 keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive");
1188 } else {
1189 // HTTP/1.1 responses default to keep-alive
1190 keep_alive = !LowerCaseEqualsASCII(connection_val, "close");
1191 } 1204 }
1192 1205 return http_version_ != HttpVersion(1, 0);
1193 return keep_alive;
1194 } 1206 }
1195 1207
1196 bool HttpResponseHeaders::HasStrongValidators() const { 1208 bool HttpResponseHeaders::HasStrongValidators() const {
1197 std::string etag_header; 1209 std::string etag_header;
1198 EnumerateHeader(NULL, "etag", &etag_header); 1210 EnumerateHeader(NULL, "etag", &etag_header);
1199 std::string last_modified_header; 1211 std::string last_modified_header;
1200 EnumerateHeader(NULL, "Last-Modified", &last_modified_header); 1212 EnumerateHeader(NULL, "Last-Modified", &last_modified_header);
1201 std::string date_header; 1213 std::string date_header;
1202 EnumerateHeader(NULL, "Date", &date_header); 1214 EnumerateHeader(NULL, "Date", &date_header);
1203 return HttpUtil::HasStrongValidators(GetHttpVersion(), 1215 return HttpUtil::HasStrongValidators(GetHttpVersion(),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 return true; 1409 return true;
1398 } 1410 }
1399 1411
1400 bool HttpResponseHeaders::IsChunkEncoded() const { 1412 bool HttpResponseHeaders::IsChunkEncoded() const {
1401 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1413 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1402 return GetHttpVersion() >= HttpVersion(1, 1) && 1414 return GetHttpVersion() >= HttpVersion(1, 1) &&
1403 HasHeaderValue("Transfer-Encoding", "chunked"); 1415 HasHeaderValue("Transfer-Encoding", "chunked");
1404 } 1416 }
1405 1417
1406 } // namespace net 1418 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698