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

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: 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
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 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool HttpResponseHeaders::IsKeepAlive() const { 1172 bool HttpResponseHeaders::IsKeepAlive() const {
1173 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is
1174 // meaningful when we don't know that this response was from a proxy, but
1175 // Mozilla also does this, so we'll do the same.
1176 static const char* kConnectionHeaders[] = {"connection", "proxy-connection"};
1177 struct KeepAliveToken {
1178 const char* token;
1179 bool keep_alive;
1180 };
1181 static const KeepAliveToken kKeepAliveTokens[] = {{"keep-alive", true},
1182 {"close", false}};
1183
1173 if (http_version_ < HttpVersion(1, 0)) 1184 if (http_version_ < HttpVersion(1, 0))
1174 return false; 1185 return false;
1175 1186
1176 // NOTE: It is perhaps risky to assume that a Proxy-Connection header is 1187 for (const char* header : kConnectionHeaders) {
rvargas (doing something else) 2014/10/15 22:55:21 nit: We need a comment somewhere stating that we g
Adam Rice 2014/10/16 11:29:38 Done.
1177 // meaningful when we don't know that this response was from a proxy, but 1188 void* iterator = nullptr;
1178 // Mozilla also does this, so we'll do the same. 1189 std::string token;
1179 std::string connection_val; 1190 while (EnumerateHeader(&iterator, header, &token)) {
1180 if (!EnumerateHeader(NULL, "connection", &connection_val)) 1191 for (const KeepAliveToken& keep_alive_token : kKeepAliveTokens) {
1181 EnumerateHeader(NULL, "proxy-connection", &connection_val); 1192 if (LowerCaseEqualsASCII(token, keep_alive_token.token))
1182 1193 return keep_alive_token.keep_alive;
1183 bool keep_alive; 1194 }
1184 1195 }
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 } 1196 }
1192 1197 return http_version_ != HttpVersion(1, 0);
1193 return keep_alive;
1194 } 1198 }
1195 1199
1196 bool HttpResponseHeaders::HasStrongValidators() const { 1200 bool HttpResponseHeaders::HasStrongValidators() const {
1197 std::string etag_header; 1201 std::string etag_header;
1198 EnumerateHeader(NULL, "etag", &etag_header); 1202 EnumerateHeader(NULL, "etag", &etag_header);
1199 std::string last_modified_header; 1203 std::string last_modified_header;
1200 EnumerateHeader(NULL, "Last-Modified", &last_modified_header); 1204 EnumerateHeader(NULL, "Last-Modified", &last_modified_header);
1201 std::string date_header; 1205 std::string date_header;
1202 EnumerateHeader(NULL, "Date", &date_header); 1206 EnumerateHeader(NULL, "Date", &date_header);
1203 return HttpUtil::HasStrongValidators(GetHttpVersion(), 1207 return HttpUtil::HasStrongValidators(GetHttpVersion(),
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 return true; 1401 return true;
1398 } 1402 }
1399 1403
1400 bool HttpResponseHeaders::IsChunkEncoded() const { 1404 bool HttpResponseHeaders::IsChunkEncoded() const {
1401 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies. 1405 // Ignore spurious chunked responses from HTTP/1.0 servers and proxies.
1402 return GetHttpVersion() >= HttpVersion(1, 1) && 1406 return GetHttpVersion() >= HttpVersion(1, 1) &&
1403 HasHeaderValue("Transfer-Encoding", "chunked"); 1407 HasHeaderValue("Transfer-Encoding", "chunked");
1404 } 1408 }
1405 1409
1406 } // namespace net 1410 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | net/http/http_response_headers_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698