| 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_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 (*headers)[status_key] = std::string(after_version + 1, after_status); | 166 (*headers)[status_key] = std::string(after_version + 1, after_status); |
| 167 | 167 |
| 168 size_t iter = 0; | 168 size_t iter = 0; |
| 169 std::string raw_name, value; | 169 std::string raw_name, value; |
| 170 while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) { | 170 while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) { |
| 171 std::string name = base::ToLowerASCII(raw_name); | 171 std::string name = base::ToLowerASCII(raw_name); |
| 172 AddSpdyHeader(name, value, headers); | 172 AddSpdyHeader(name, value, headers); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 static_assert(HIGHEST - LOWEST < 4 && HIGHEST - MINIMUM_PRIORITY < 5, | 176 static_assert(HIGHEST - LOWEST < 4 && HIGHEST - MINIMUM_PRIORITY < 6, |
| 177 "request priority incompatible with spdy"); | 177 "request priority incompatible with spdy"); |
| 178 | 178 |
| 179 SpdyPriority ConvertRequestPriorityToSpdyPriority( | 179 SpdyPriority ConvertRequestPriorityToSpdyPriority( |
| 180 const RequestPriority priority, | 180 const RequestPriority priority, |
| 181 SpdyMajorVersion protocol_version) { | 181 SpdyMajorVersion protocol_version) { |
| 182 DCHECK_GE(priority, MINIMUM_PRIORITY); | 182 DCHECK_GE(priority, MINIMUM_PRIORITY); |
| 183 DCHECK_LE(priority, MAXIMUM_PRIORITY); | 183 DCHECK_LE(priority, MAXIMUM_PRIORITY); |
| 184 return static_cast<SpdyPriority>(MAXIMUM_PRIORITY - priority); | 184 return static_cast<SpdyPriority>(MAXIMUM_PRIORITY - priority + |
| 185 kV3HighestPriority); |
| 185 } | 186 } |
| 186 | 187 |
| 187 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( | 188 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( |
| 188 SpdyPriority priority, | 189 SpdyPriority priority, |
| 189 SpdyMajorVersion protocol_version) { | 190 SpdyMajorVersion protocol_version) { |
| 190 // Handle invalid values gracefully. | 191 // Handle invalid values gracefully. |
| 191 // Note that SpdyPriority is not an enum, hence the magic constants. | 192 return ((priority - kV3HighestPriority) > |
| 192 return (priority >= 5) ? | 193 (MAXIMUM_PRIORITY - MINIMUM_PRIORITY)) |
| 193 IDLE : static_cast<RequestPriority>(4 - priority); | 194 ? IDLE |
| 195 : static_cast<RequestPriority>(MAXIMUM_PRIORITY - |
| 196 (priority - kV3HighestPriority)); |
| 194 } | 197 } |
| 195 | 198 |
| 196 NET_EXPORT_PRIVATE void ConvertHeaderBlockToHttpRequestHeaders( | 199 NET_EXPORT_PRIVATE void ConvertHeaderBlockToHttpRequestHeaders( |
| 197 const SpdyHeaderBlock& spdy_headers, | 200 const SpdyHeaderBlock& spdy_headers, |
| 198 HttpRequestHeaders* http_headers) { | 201 HttpRequestHeaders* http_headers) { |
| 199 for (const auto& it : spdy_headers) { | 202 for (const auto& it : spdy_headers) { |
| 200 base::StringPiece key = it.first; | 203 base::StringPiece key = it.first; |
| 201 if (key[0] == ':') { | 204 if (key[0] == ':') { |
| 202 key.remove_prefix(1); | 205 key.remove_prefix(1); |
| 203 } | 206 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 223 url.append(it->second.as_string()); | 226 url.append(it->second.as_string()); |
| 224 | 227 |
| 225 it = headers.find(":path"); | 228 it = headers.find(":path"); |
| 226 if (it == headers.end()) | 229 if (it == headers.end()) |
| 227 return GURL(); | 230 return GURL(); |
| 228 url.append(it->second.as_string()); | 231 url.append(it->second.as_string()); |
| 229 return GURL(url); | 232 return GURL(url); |
| 230 } | 233 } |
| 231 | 234 |
| 232 } // namespace net | 235 } // namespace net |
| OLD | NEW |