| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/spdy_http_utils.h" | 5 #include "net/spdy/spdy_http_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 response->headers = new HttpResponseHeaders(raw_headers); | 81 response->headers = new HttpResponseHeaders(raw_headers); |
| 82 response->was_fetched_via_spdy = true; | 82 response->was_fetched_via_spdy = true; |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, | 86 void CreateSpdyHeadersFromHttpRequest(const HttpRequestInfo& info, |
| 87 const HttpRequestHeaders& request_headers, | 87 const HttpRequestHeaders& request_headers, |
| 88 SpdyHeaderBlock* headers, | 88 SpdyHeaderBlock* headers, |
| 89 SpdyMajorVersion protocol_version, | 89 SpdyMajorVersion protocol_version, |
| 90 bool direct) { | 90 bool direct) { |
| 91 | |
| 92 HttpRequestHeaders::Iterator it(request_headers); | 91 HttpRequestHeaders::Iterator it(request_headers); |
| 93 while (it.GetNext()) { | 92 while (it.GetNext()) { |
| 94 std::string name = StringToLowerASCII(it.name()); | 93 std::string name = StringToLowerASCII(it.name()); |
| 95 if (name == "connection" || name == "proxy-connection" || | 94 if (name == "connection" || name == "proxy-connection" || |
| 96 name == "transfer-encoding" || name == "host") { | 95 name == "transfer-encoding" || name == "host") { |
| 97 continue; | 96 continue; |
| 98 } | 97 } |
| 99 if (headers->find(name) == headers->end()) { | 98 if (headers->find(name) == headers->end()) { |
| 100 (*headers)[name] = it.value(); | 99 (*headers)[name] = it.value(); |
| 101 } else { | 100 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 122 (*headers)[":host"] = GetHostAndOptionalPort(info.url); | 121 (*headers)[":host"] = GetHostAndOptionalPort(info.url); |
| 123 } else { | 122 } else { |
| 124 (*headers)[":authority"] = GetHostAndOptionalPort(info.url); | 123 (*headers)[":authority"] = GetHostAndOptionalPort(info.url); |
| 125 } | 124 } |
| 126 (*headers)[":method"] = info.method; | 125 (*headers)[":method"] = info.method; |
| 127 (*headers)[":scheme"] = info.url.scheme(); | 126 (*headers)[":scheme"] = info.url.scheme(); |
| 128 (*headers)[":path"] = HttpUtil::PathForRequest(info.url); | 127 (*headers)[":path"] = HttpUtil::PathForRequest(info.url); |
| 129 } | 128 } |
| 130 } | 129 } |
| 131 | 130 |
| 132 COMPILE_ASSERT(HIGHEST - LOWEST < 4 && | 131 COMPILE_ASSERT(HIGHEST - LOWEST < 4 && HIGHEST - MINIMUM_PRIORITY < 5, |
| 133 HIGHEST - MINIMUM_PRIORITY < 5, | |
| 134 request_priority_incompatible_with_spdy); | 132 request_priority_incompatible_with_spdy); |
| 135 | 133 |
| 136 SpdyPriority ConvertRequestPriorityToSpdyPriority( | 134 SpdyPriority ConvertRequestPriorityToSpdyPriority( |
| 137 const RequestPriority priority, | 135 const RequestPriority priority, |
| 138 SpdyMajorVersion protocol_version) { | 136 SpdyMajorVersion protocol_version) { |
| 139 DCHECK_GE(priority, MINIMUM_PRIORITY); | 137 DCHECK_GE(priority, MINIMUM_PRIORITY); |
| 140 DCHECK_LE(priority, MAXIMUM_PRIORITY); | 138 DCHECK_LE(priority, MAXIMUM_PRIORITY); |
| 141 if (protocol_version == SPDY2) { | 139 if (protocol_version == SPDY2) { |
| 142 // SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities. | 140 // SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities. |
| 143 // Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0. | 141 // Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0. |
| 144 if (priority > LOWEST) { | 142 if (priority > LOWEST) { |
| 145 return static_cast<SpdyPriority>(HIGHEST - priority); | 143 return static_cast<SpdyPriority>(HIGHEST - priority); |
| 146 } else { | 144 } else { |
| 147 return static_cast<SpdyPriority>(HIGHEST - priority - 1); | 145 return static_cast<SpdyPriority>(HIGHEST - priority - 1); |
| 148 } | 146 } |
| 149 } else { | 147 } else { |
| 150 return static_cast<SpdyPriority>(HIGHEST - priority); | 148 return static_cast<SpdyPriority>(HIGHEST - priority); |
| 151 } | 149 } |
| 152 } | 150 } |
| 153 | 151 |
| 154 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( | 152 NET_EXPORT_PRIVATE RequestPriority |
| 155 SpdyPriority priority, | 153 ConvertSpdyPriorityToRequestPriority(SpdyPriority priority, |
| 156 SpdyMajorVersion protocol_version) { | 154 SpdyMajorVersion protocol_version) { |
| 157 // Handle invalid values gracefully, and pick LOW to map 2 back | 155 // Handle invalid values gracefully, and pick LOW to map 2 back |
| 158 // to for SPDY/2. | 156 // to for SPDY/2. |
| 159 SpdyPriority idle_cutoff = (protocol_version == SPDY2) ? 3 : 5; | 157 SpdyPriority idle_cutoff = (protocol_version == SPDY2) ? 3 : 5; |
| 160 return (priority >= idle_cutoff) ? | 158 return (priority >= idle_cutoff) |
| 161 IDLE : static_cast<RequestPriority>(HIGHEST - priority); | 159 ? IDLE |
| 160 : static_cast<RequestPriority>(HIGHEST - priority); |
| 162 } | 161 } |
| 163 | 162 |
| 164 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, | 163 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, |
| 165 SpdyMajorVersion protocol_version, | 164 SpdyMajorVersion protocol_version, |
| 166 bool pushed) { | 165 bool pushed) { |
| 167 // SPDY 2 server push urls are specified in a single "url" header. | 166 // SPDY 2 server push urls are specified in a single "url" header. |
| 168 if (pushed && protocol_version == SPDY2) { | 167 if (pushed && protocol_version == SPDY2) { |
| 169 std::string url; | 168 std::string url; |
| 170 SpdyHeaderBlock::const_iterator it; | 169 SpdyHeaderBlock::const_iterator it; |
| 171 it = headers.find("url"); | 170 it = headers.find("url"); |
| 172 if (it != headers.end()) | 171 if (it != headers.end()) |
| 173 url = it->second; | 172 url = it->second; |
| 174 return GURL(url); | 173 return GURL(url); |
| 175 } | 174 } |
| 176 | 175 |
| 177 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; | 176 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; |
| 178 const char* host_header = protocol_version >= SPDY4 ? ":authority" : | 177 const char* host_header = |
| 179 (protocol_version >= SPDY3 ? ":host" : "host"); | 178 protocol_version >= SPDY4 |
| 179 ? ":authority" |
| 180 : (protocol_version >= SPDY3 ? ":host" : "host"); |
| 180 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; | 181 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; |
| 181 | 182 |
| 182 std::string scheme; | 183 std::string scheme; |
| 183 std::string host_port; | 184 std::string host_port; |
| 184 std::string path; | 185 std::string path; |
| 185 SpdyHeaderBlock::const_iterator it; | 186 SpdyHeaderBlock::const_iterator it; |
| 186 it = headers.find(scheme_header); | 187 it = headers.find(scheme_header); |
| 187 if (it != headers.end()) | 188 if (it != headers.end()) |
| 188 scheme = it->second; | 189 scheme = it->second; |
| 189 it = headers.find(host_header); | 190 it = headers.find(host_header); |
| 190 if (it != headers.end()) | 191 if (it != headers.end()) |
| 191 host_port = it->second; | 192 host_port = it->second; |
| 192 it = headers.find(path_header); | 193 it = headers.find(path_header); |
| 193 if (it != headers.end()) | 194 if (it != headers.end()) |
| 194 path = it->second; | 195 path = it->second; |
| 195 | 196 |
| 196 std::string url = (scheme.empty() || host_port.empty() || path.empty()) | 197 std::string url = (scheme.empty() || host_port.empty() || path.empty()) |
| 197 ? std::string() | 198 ? std::string() |
| 198 : scheme + "://" + host_port + path; | 199 : scheme + "://" + host_port + path; |
| 199 return GURL(url); | 200 return GURL(url); |
| 200 } | 201 } |
| 201 | 202 |
| 202 } // namespace net | 203 } // namespace net |
| OLD | NEW |