Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Side by Side Diff: net/spdy/spdy_http_utils.cc

Issue 754433003: Update from https://crrev.com/305340 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_http_stream_unittest.cc ('k') | net/spdy/spdy_http_utils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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>(MAXIMUM_PRIORITY - priority);
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 // Note that SpdyPriority is not an enum, hence the magic constants.
191 SpdyPriority idle_cutoff = (protocol_version == SPDY2) ? 3 : 5; 181 return (priority >= 5) ?
192 return (priority >= idle_cutoff) ? 182 IDLE : static_cast<RequestPriority>(4 - priority);
193 IDLE : static_cast<RequestPriority>(HIGHEST - priority);
194 } 183 }
195 184
196 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, 185 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers,
197 SpdyMajorVersion protocol_version, 186 SpdyMajorVersion protocol_version,
198 bool pushed) { 187 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"; 188 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme";
210 const char* host_header = protocol_version >= SPDY4 ? ":authority" : 189 const char* host_header = protocol_version >= SPDY4 ? ":authority" :
211 (protocol_version >= SPDY3 ? ":host" : "host"); 190 (protocol_version >= SPDY3 ? ":host" : "host");
212 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; 191 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url";
213 192
214 std::string scheme; 193 std::string scheme;
215 std::string host_port; 194 std::string host_port;
216 std::string path; 195 std::string path;
217 SpdyHeaderBlock::const_iterator it; 196 SpdyHeaderBlock::const_iterator it;
218 it = headers.find(scheme_header); 197 it = headers.find(scheme_header);
219 if (it != headers.end()) 198 if (it != headers.end())
220 scheme = it->second; 199 scheme = it->second;
221 it = headers.find(host_header); 200 it = headers.find(host_header);
222 if (it != headers.end()) 201 if (it != headers.end())
223 host_port = it->second; 202 host_port = it->second;
224 it = headers.find(path_header); 203 it = headers.find(path_header);
225 if (it != headers.end()) 204 if (it != headers.end())
226 path = it->second; 205 path = it->second;
227 206
228 std::string url = (scheme.empty() || host_port.empty() || path.empty()) 207 std::string url = (scheme.empty() || host_port.empty() || path.empty())
229 ? std::string() 208 ? std::string()
230 : scheme + "://" + host_port + path; 209 : scheme + "://" + host_port + path;
231 return GURL(url); 210 return GURL(url);
232 } 211 }
233 212
234 } // namespace net 213 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_stream_unittest.cc ('k') | net/spdy/spdy_http_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698