Index: net/spdy/spdy_http_utils.cc |
diff --git a/net/spdy/spdy_http_utils.cc b/net/spdy/spdy_http_utils.cc |
index 21012f23fc1a854fb7857fe229fc9e960a99b19c..f0c4544332868c030abd02e6791c2390c3fef216 100644 |
--- a/net/spdy/spdy_http_utils.cc |
+++ b/net/spdy/spdy_http_utils.cc |
@@ -21,24 +21,30 @@ |
namespace net { |
bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers, |
- int protocol_version, |
+ SpdyMajorVersion protocol_version, |
HttpResponseInfo* response) { |
- std::string status_key = (protocol_version >= 3) ? ":status" : "status"; |
- std::string version_key = (protocol_version >= 3) ? ":version" : "version"; |
+ std::string status_key = |
+ (protocol_version >= SPDY3) ? ":status" : "status"; |
+ std::string version_key = |
+ (protocol_version >= SPDY3) ? ":version" : "version"; |
std::string version; |
std::string status; |
- // The "status" and "version" headers are required. |
+ // The "status" (and "version" headers for SPDY3 and below) are required. |
SpdyHeaderBlock::const_iterator it; |
it = headers.find(status_key); |
if (it == headers.end()) |
return false; |
status = it->second; |
- it = headers.find(version_key); |
- if (it == headers.end()) |
- return false; |
- version = it->second; |
+ if (protocol_version < SPDY4) { |
+ it = headers.find(version_key); |
+ if (it == headers.end()) |
+ return false; |
+ version = it->second; |
+ } else { |
+ version = "HTTP/1.1"; |
+ } |
std::string raw_headers(version); |
raw_headers.push_back(' '); |
@@ -63,7 +69,7 @@ bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers, |
tval = value.substr(start, (end - start)); |
else |
tval = value.substr(start); |
- if (protocol_version >= 3 && it->first[0] == ':') |
+ if (protocol_version >= SPDY3 && it->first[0] == ':') |
raw_headers.append(it->first.substr(1)); |
else |
raw_headers.append(it->first); |
@@ -82,7 +88,7 @@ bool SpdyHeadersToHttpResponse(const SpdyHeaderBlock& headers, |
void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
const HttpRequestHeaders& request_headers, |
SpdyHeaderBlock* headers, |
- int protocol_version, |
+ SpdyMajorVersion protocol_version, |
bool direct) { |
HttpRequestHeaders::Iterator it(request_headers); |
@@ -103,7 +109,7 @@ void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
} |
static const char kHttpProtocolVersion[] = "HTTP/1.1"; |
- if (protocol_version < 3) { |
+ if (protocol_version < SPDY3) { |
(*headers)["version"] = kHttpProtocolVersion; |
(*headers)["method"] = info.method; |
(*headers)["host"] = GetHostAndOptionalPort(info.url); |
@@ -113,7 +119,7 @@ void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
else |
(*headers)["url"] = HttpUtil::SpecForRequest(info.url); |
} else { |
- (*headers)[":version"] = kHttpProtocolVersion; |
+ // Don't send :version for HTTP/2. |
(*headers)[":method"] = info.method; |
(*headers)[":host"] = GetHostAndOptionalPort(info.url); |
(*headers)[":scheme"] = info.url.scheme(); |
@@ -129,10 +135,10 @@ COMPILE_ASSERT(HIGHEST - LOWEST < 4 && |
SpdyPriority ConvertRequestPriorityToSpdyPriority( |
const RequestPriority priority, |
- int protocol_version) { |
+ SpdyMajorVersion protocol_version) { |
DCHECK_GE(priority, MINIMUM_PRIORITY); |
DCHECK_LT(priority, NUM_PRIORITIES); |
- if (protocol_version == 2) { |
+ if (protocol_version == SPDY2) { |
// SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities. |
// Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0. |
if (priority > LOWEST) { |
@@ -147,19 +153,19 @@ SpdyPriority ConvertRequestPriorityToSpdyPriority( |
NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( |
SpdyPriority priority, |
- int protocol_version) { |
+ SpdyMajorVersion protocol_version) { |
// Handle invalid values gracefully, and pick LOW to map 2 back |
// to for SPDY/2. |
- SpdyPriority idle_cutoff = (protocol_version == 2) ? 3 : 5; |
+ SpdyPriority idle_cutoff = (protocol_version == SPDY2) ? 3 : 5; |
return (priority >= idle_cutoff) ? |
IDLE : static_cast<RequestPriority>(HIGHEST - priority); |
} |
GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, |
- int protocol_version, |
+ SpdyMajorVersion protocol_version, |
bool pushed) { |
// SPDY 2 server push urls are specified in a single "url" header. |
- if (pushed && protocol_version == 2) { |
+ if (pushed && protocol_version == SPDY2) { |
std::string url; |
SpdyHeaderBlock::const_iterator it; |
it = headers.find("url"); |
@@ -168,9 +174,9 @@ GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, |
return GURL(url); |
} |
- const char* scheme_header = protocol_version >= 3 ? ":scheme" : "scheme"; |
- const char* host_header = protocol_version >= 3 ? ":host" : "host"; |
- const char* path_header = protocol_version >= 3 ? ":path" : "url"; |
+ const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; |
+ const char* host_header = protocol_version >= SPDY3 ? ":host" : "host"; |
+ const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; |
std::string scheme; |
std::string host_port; |