diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 22:02:38 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-05 22:02:38 +0000 |
commit | 1a616d92fc1bdafcceda50939e6a5b72f4885a98 (patch) | |
tree | e85ccb221c85ed8706e5ff1c3547980929a8f91b /net/http | |
parent | fa080a88617754f2b4a75a482c546422b9ca4fe0 (diff) | |
download | chromium_src-1a616d92fc1bdafcceda50939e6a5b72f4885a98.zip chromium_src-1a616d92fc1bdafcceda50939e6a5b72f4885a98.tar.gz chromium_src-1a616d92fc1bdafcceda50939e6a5b72f4885a98.tar.bz2 |
Clean up HttpResponseHeaders::IsKeepAlive. Use the parsed
HTTP version in the http_version_ member. Pass NULL to
EnumerateHeader.
R=eroman
Review URL: http://codereview.chromium.org/40137
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11045 0039d316-1c4b-4281-b951-d872f2087c98
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); |