Chromium Code Reviews| 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 { |