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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 (*headers)[":status"] = std::string(after_version + 1, after_status); | 120 (*headers)[":status"] = std::string(after_version + 1, after_status); |
121 | 121 |
122 size_t iter = 0; | 122 size_t iter = 0; |
123 std::string raw_name, value; | 123 std::string raw_name, value; |
124 while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) { | 124 while (response_headers.EnumerateHeaderLines(&iter, &raw_name, &value)) { |
125 std::string name = base::ToLowerASCII(raw_name); | 125 std::string name = base::ToLowerASCII(raw_name); |
126 AddSpdyHeader(name, value, headers); | 126 AddSpdyHeader(name, value, headers); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 static_assert(HIGHEST - LOWEST < 4 && HIGHEST - MINIMUM_PRIORITY < 5, | 130 static_assert(HIGHEST - LOWEST < 4 && HIGHEST - MINIMUM_PRIORITY < 6, |
131 "request priority incompatible with spdy"); | 131 "request priority incompatible with spdy"); |
132 | 132 |
133 SpdyPriority ConvertRequestPriorityToSpdyPriority( | 133 SpdyPriority ConvertRequestPriorityToSpdyPriority( |
134 const RequestPriority priority) { | 134 const RequestPriority priority) { |
135 DCHECK_GE(priority, MINIMUM_PRIORITY); | 135 DCHECK_GE(priority, MINIMUM_PRIORITY); |
136 DCHECK_LE(priority, MAXIMUM_PRIORITY); | 136 DCHECK_LE(priority, MAXIMUM_PRIORITY); |
137 return static_cast<SpdyPriority>(MAXIMUM_PRIORITY - priority); | 137 return static_cast<SpdyPriority>(MAXIMUM_PRIORITY - priority + |
| 138 kV3HighestPriority); |
138 } | 139 } |
139 | 140 |
140 NET_EXPORT_PRIVATE RequestPriority | 141 NET_EXPORT_PRIVATE RequestPriority |
141 ConvertSpdyPriorityToRequestPriority(SpdyPriority priority) { | 142 ConvertSpdyPriorityToRequestPriority(SpdyPriority priority) { |
142 // Handle invalid values gracefully. | 143 // Handle invalid values gracefully. |
143 // Note that SpdyPriority is not an enum, hence the magic constants. | 144 return ((priority - kV3HighestPriority) > |
144 return (priority >= 5) ? | 145 (MAXIMUM_PRIORITY - MINIMUM_PRIORITY)) |
145 IDLE : static_cast<RequestPriority>(4 - priority); | 146 ? IDLE |
| 147 : static_cast<RequestPriority>(MAXIMUM_PRIORITY - |
| 148 (priority - kV3HighestPriority)); |
146 } | 149 } |
147 | 150 |
148 NET_EXPORT_PRIVATE void ConvertHeaderBlockToHttpRequestHeaders( | 151 NET_EXPORT_PRIVATE void ConvertHeaderBlockToHttpRequestHeaders( |
149 const SpdyHeaderBlock& spdy_headers, | 152 const SpdyHeaderBlock& spdy_headers, |
150 HttpRequestHeaders* http_headers) { | 153 HttpRequestHeaders* http_headers) { |
151 for (const auto& it : spdy_headers) { | 154 for (const auto& it : spdy_headers) { |
152 base::StringPiece key = it.first; | 155 base::StringPiece key = it.first; |
153 if (key[0] == ':') { | 156 if (key[0] == ':') { |
154 key.remove_prefix(1); | 157 key.remove_prefix(1); |
155 } | 158 } |
(...skipping 18 matching lines...) Expand all Loading... |
174 url.append(it->second.as_string()); | 177 url.append(it->second.as_string()); |
175 | 178 |
176 it = headers.find(":path"); | 179 it = headers.find(":path"); |
177 if (it == headers.end()) | 180 if (it == headers.end()) |
178 return GURL(); | 181 return GURL(); |
179 url.append(it->second.as_string()); | 182 url.append(it->second.as_string()); |
180 return GURL(url); | 183 return GURL(url); |
181 } | 184 } |
182 | 185 |
183 } // namespace net | 186 } // namespace net |
OLD | NEW |