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

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: Add comments and Proxy-Connection tests. 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
« no previous file with comments | « no previous file | net/http/http_response_headers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..773ba0b0c3897b33820747f25e6d7c2f167f255d 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -1169,28 +1169,40 @@ bool HttpResponseHeaders::GetTimeValuedHeader(const std::string& name,
return Time::FromUTCString(value.c_str(), result);
}
+// We accept the first value of "close" or "keep-alive" in a Connection or
+// Proxy-Connection header, in that order. Obeying "keep-alive" in HTTP/1.1 or
+// "close" in 1.0 is not strictly standards-compliant, but we'd like to
+// avoid looking at the Proxy-Connection header whenever it is reasonable to do
+// so.
+// TODO(ricea): Measure real-world usage of the "Proxy-Connection" header,
+// with a view to reducing support for it in order to make our Connection header
+// handling more RFC 7230 compliant.
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) {
+ 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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698