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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 | 163 |
164 COMPILE_ASSERT(HIGHEST - LOWEST < 4 && | 164 COMPILE_ASSERT(HIGHEST - LOWEST < 4 && |
165 HIGHEST - MINIMUM_PRIORITY < 5, | 165 HIGHEST - MINIMUM_PRIORITY < 5, |
166 request_priority_incompatible_with_spdy); | 166 request_priority_incompatible_with_spdy); |
167 | 167 |
168 SpdyPriority ConvertRequestPriorityToSpdyPriority( | 168 SpdyPriority ConvertRequestPriorityToSpdyPriority( |
169 const RequestPriority priority, | 169 const RequestPriority priority, |
170 SpdyMajorVersion protocol_version) { | 170 SpdyMajorVersion protocol_version) { |
171 DCHECK_GE(priority, MINIMUM_PRIORITY); | 171 DCHECK_GE(priority, MINIMUM_PRIORITY); |
172 DCHECK_LE(priority, MAXIMUM_PRIORITY); | 172 DCHECK_LE(priority, MAXIMUM_PRIORITY); |
173 if (protocol_version == SPDY2) { | 173 return static_cast<SpdyPriority>(HIGHEST - priority); |
asanka
2014/11/10 19:18:37
Why HIGHEST here vs. MAXIMUM_PRIORITY when convert
Bence
2014/11/10 22:52:09
Done.
| |
174 // SPDY 2 only has 2 bits of priority, but we have 5 RequestPriorities. | |
175 // Map IDLE => 3, LOWEST => 2, LOW => 2, MEDIUM => 1, HIGHEST => 0. | |
176 if (priority > LOWEST) { | |
177 return static_cast<SpdyPriority>(HIGHEST - priority); | |
178 } else { | |
179 return static_cast<SpdyPriority>(HIGHEST - priority - 1); | |
180 } | |
181 } else { | |
182 return static_cast<SpdyPriority>(HIGHEST - priority); | |
183 } | |
184 } | 174 } |
185 | 175 |
186 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( | 176 NET_EXPORT_PRIVATE RequestPriority ConvertSpdyPriorityToRequestPriority( |
187 SpdyPriority priority, | 177 SpdyPriority priority, |
188 SpdyMajorVersion protocol_version) { | 178 SpdyMajorVersion protocol_version) { |
189 // Handle invalid values gracefully, and pick LOW to map 2 back | 179 // Handle invalid values gracefully. |
190 // to for SPDY/2. | 180 return (priority >= MAXIMUM_PRIORITY) ? |
asanka
2014/11/10 19:18:37
This compares a SpdyPriority to a RequestPriority.
Bence
2014/11/10 22:52:09
Good catch, thanks. Done.
| |
191 SpdyPriority idle_cutoff = (protocol_version == SPDY2) ? 3 : 5; | 181 IDLE : static_cast<RequestPriority>(MAXIMUM_PRIORITY - priority); |
192 return (priority >= idle_cutoff) ? | |
193 IDLE : static_cast<RequestPriority>(HIGHEST - priority); | |
194 } | 182 } |
195 | 183 |
196 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, | 184 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, |
197 SpdyMajorVersion protocol_version, | 185 SpdyMajorVersion protocol_version, |
198 bool pushed) { | 186 bool pushed) { |
199 // SPDY 2 server push urls are specified in a single "url" header. | |
200 if (pushed && protocol_version == SPDY2) { | |
201 std::string url; | |
202 SpdyHeaderBlock::const_iterator it; | |
203 it = headers.find("url"); | |
204 if (it != headers.end()) | |
205 url = it->second; | |
206 return GURL(url); | |
207 } | |
208 | |
209 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; | 187 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; |
210 const char* host_header = protocol_version >= SPDY4 ? ":authority" : | 188 const char* host_header = protocol_version >= SPDY4 ? ":authority" : |
211 (protocol_version >= SPDY3 ? ":host" : "host"); | 189 (protocol_version >= SPDY3 ? ":host" : "host"); |
212 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; | 190 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; |
213 | 191 |
214 std::string scheme; | 192 std::string scheme; |
215 std::string host_port; | 193 std::string host_port; |
216 std::string path; | 194 std::string path; |
217 SpdyHeaderBlock::const_iterator it; | 195 SpdyHeaderBlock::const_iterator it; |
218 it = headers.find(scheme_header); | 196 it = headers.find(scheme_header); |
219 if (it != headers.end()) | 197 if (it != headers.end()) |
220 scheme = it->second; | 198 scheme = it->second; |
221 it = headers.find(host_header); | 199 it = headers.find(host_header); |
222 if (it != headers.end()) | 200 if (it != headers.end()) |
223 host_port = it->second; | 201 host_port = it->second; |
224 it = headers.find(path_header); | 202 it = headers.find(path_header); |
225 if (it != headers.end()) | 203 if (it != headers.end()) |
226 path = it->second; | 204 path = it->second; |
227 | 205 |
228 std::string url = (scheme.empty() || host_port.empty() || path.empty()) | 206 std::string url = (scheme.empty() || host_port.empty() || path.empty()) |
229 ? std::string() | 207 ? std::string() |
230 : scheme + "://" + host_port + path; | 208 : scheme + "://" + host_port + path; |
231 return GURL(url); | 209 return GURL(url); |
232 } | 210 } |
233 | 211 |
234 } // namespace net | 212 } // namespace net |
OLD | NEW |