diff options
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_response_headers.cc | 12 | ||||
-rw-r--r-- | net/http/http_response_headers_unittest.cc | 23 |
2 files changed, 27 insertions, 8 deletions
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 536a571..8c2a0b3 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -924,23 +924,19 @@ bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name, } bool HttpResponseHeaders::IsKeepAlive() const { - const char kPrefix[] = "HTTP/1.0"; - const size_t kPrefixLen = arraysize(kPrefix) - 1; - if (raw_headers_.size() < kPrefixLen) // Lacking a status line? + 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; - void* iter = NULL; - if (!EnumerateHeader(&iter, "connection", &connection_val)) - EnumerateHeader(&iter, "proxy-connection", &connection_val); + if (!EnumerateHeader(NULL, "connection", &connection_val)) + EnumerateHeader(NULL, "proxy-connection", &connection_val); bool keep_alive; - if (std::equal(raw_headers_.begin(), - raw_headers_.begin() + kPrefixLen, kPrefix)) { + if (http_version_ == HttpVersion(1, 0)) { // HTTP/1.0 responses default to NOT keep-alive keep_alive = LowerCaseEqualsASCII(connection_val, "keep-alive"); } else { diff --git a/net/http/http_response_headers_unittest.cc b/net/http/http_response_headers_unittest.cc index a8d76304..9c7ce75 100644 --- a/net/http/http_response_headers_unittest.cc +++ b/net/http/http_response_headers_unittest.cc @@ -1042,6 +1042,17 @@ TEST(HttpResponseHeadersTest, IsKeepAlive) { const char* headers; bool expected_keep_alive; } tests[] = { + // The status line fabricated by HttpNetworkTransaction for a 0.9 response. + // Treated as 0.9. + { "HTTP/0.9 200 OK", + false + }, + // This could come from a broken server. Treated as 1.0 because it has a + // header. + { "HTTP/0.9 200 OK\n" + "connection: keep-alive\n", + true + }, { "HTTP/1.1 200 OK\n", true }, @@ -1072,10 +1083,22 @@ TEST(HttpResponseHeadersTest, IsKeepAlive) { "connection: keep-alive\n", true }, + { "HTTP/1.0 200 OK\n" + "proxy-connection: close\n", + false + }, + { "HTTP/1.0 200 OK\n" + "proxy-connection: keep-alive\n", + true + }, { "HTTP/1.1 200 OK\n" "proxy-connection: close\n", false }, + { "HTTP/1.1 200 OK\n" + "proxy-connection: keep-alive\n", + true + }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { string headers(tests[i].headers); |