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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 3a9f7e04fe0c4bad6a232ae52270e55427532d03..5c3436dec5946fdf955da47a3c152b1136ee5510 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -1170,27 +1170,31 @@ bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name,
}
bool HttpResponseHeaders::IsKeepAlive() const {
- if (http_version_ < HttpVersion(1, 0))
- return false;
-
// NOTE: It is perhaps risky to assume that a Proxy-Connection header is
// meaningful when we don't know that this response was from a proxy, but
// Mozilla also does this, so we'll do the same.
- std::string connection_val;
- if (!EnumerateHeader(NULL, "connection", &connection_val))
- EnumerateHeader(NULL, "proxy-connection", &connection_val);
+ static const char* kConnectionHeaders[] = {"connection", "proxy-connection"};
+ struct KeepAliveToken {
+ const char* token;
+ bool keep_alive;
+ };
+ static const KeepAliveToken kKeepAliveTokens[] = {{"keep-alive", true},
+ {"close", false}};
- bool keep_alive;
+ if (http_version_ < HttpVersion(1, 0))
+ return false;
- if (http_version_ == HttpVersion(1, 0)) {
- // HTTP/1.0 responses default to NOT keep-alive
- keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive");
- } else {
- // HTTP/1.1 responses default to keep-alive
- keep_alive = !LowerCaseEqualsASCII(connection_val, "close");
+ 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.
+ void* iterator = nullptr;
+ std::string token;
+ while (EnumerateHeader(&iterator, header, &token)) {
+ for (const KeepAliveToken& keep_alive_token : kKeepAliveTokens) {
+ if (LowerCaseEqualsASCII(token, keep_alive_token.token))
+ return keep_alive_token.keep_alive;
+ }
+ }
}
-
- return keep_alive;
+ return http_version_ != HttpVersion(1, 0);
}
bool HttpResponseHeaders::HasStrongValidators() const {
« 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