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

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

Issue 996483002: Improve code with early returns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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 | « no previous file | no next file » | 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 SpdyMajorVersion protocol_version) { 176 SpdyMajorVersion protocol_version) {
177 // Handle invalid values gracefully. 177 // Handle invalid values gracefully.
178 // Note that SpdyPriority is not an enum, hence the magic constants. 178 // Note that SpdyPriority is not an enum, hence the magic constants.
179 return (priority >= 5) ? 179 return (priority >= 5) ?
180 IDLE : static_cast<RequestPriority>(4 - priority); 180 IDLE : static_cast<RequestPriority>(4 - priority);
181 } 181 }
182 182
183 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers, 183 GURL GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers,
184 SpdyMajorVersion protocol_version, 184 SpdyMajorVersion protocol_version,
185 bool pushed) { 185 bool pushed) {
186 const char* scheme_header = protocol_version >= SPDY3 ? ":scheme" : "scheme"; 186 DCHECK_LE(SPDY3, protocol_version);
187 const char* host_header = protocol_version >= SPDY4 ? ":authority" : 187 SpdyHeaderBlock::const_iterator it = headers.find(":scheme");
188 (protocol_version >= SPDY3 ? ":host" : "host"); 188 if (it == headers.end())
189 const char* path_header = protocol_version >= SPDY3 ? ":path" : "url"; 189 return GURL();
190 std::string url = it->second;
191 url.append("://");
190 192
191 std::string scheme; 193 it = headers.find(protocol_version >= SPDY4 ? ":authority" : ":host");
192 std::string host_port; 194 if (it == headers.end())
193 std::string path; 195 return GURL();
194 SpdyHeaderBlock::const_iterator it; 196 url.append(it->second);
195 it = headers.find(scheme_header);
196 if (it != headers.end())
197 scheme = it->second;
198 it = headers.find(host_header);
199 if (it != headers.end())
200 host_port = it->second;
201 it = headers.find(path_header);
202 if (it != headers.end())
203 path = it->second;
204 197
205 std::string url = (scheme.empty() || host_port.empty() || path.empty()) 198 it = headers.find(":path");
206 ? std::string() 199 if (it == headers.end())
207 : scheme + "://" + host_port + path; 200 return GURL();
201 url.append(it->second);
208 return GURL(url); 202 return GURL(url);
209 } 203 }
210 204
211 } // namespace net 205 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698