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

Side by Side Diff: net/http/http_stream_factory.cc

Issue 1215933004: New new versions of Starts/EndsWith and SplitString in net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@starts_with
Patch Set: Created 5 years, 5 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
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/http/http_stream_factory.h" 5 #include "net/http/http_stream_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 20 matching lines...) Expand all
31 void HttpStreamFactory::ProcessAlternateProtocol( 31 void HttpStreamFactory::ProcessAlternateProtocol(
32 const base::WeakPtr<HttpServerProperties>& http_server_properties, 32 const base::WeakPtr<HttpServerProperties>& http_server_properties,
33 const std::vector<std::string>& alternate_protocol_values, 33 const std::vector<std::string>& alternate_protocol_values,
34 const HostPortPair& http_host_port_pair, 34 const HostPortPair& http_host_port_pair,
35 const HttpNetworkSession& session) { 35 const HttpNetworkSession& session) {
36 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL; 36 AlternateProtocol protocol = UNINITIALIZED_ALTERNATE_PROTOCOL;
37 int port = 0; 37 int port = 0;
38 double probability = 1; 38 double probability = 1;
39 bool is_valid = true; 39 bool is_valid = true;
40 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) { 40 for (size_t i = 0; i < alternate_protocol_values.size(); ++i) {
41 const std::string& alternate_protocol_str = alternate_protocol_values[i]; 41 base::StringPiece alternate_protocol_str = alternate_protocol_values[i];
42 if (base::StartsWithASCII(alternate_protocol_str, "p=", true)) { 42 if (base::StartsWith(alternate_protocol_str, "p=",
43 if (!base::StringToDouble(alternate_protocol_str.substr(2), 43 base::CompareCase::SENSITIVE)) {
44 if (!base::StringToDouble(alternate_protocol_str.substr(2).as_string(),
44 &probability) || 45 &probability) ||
45 probability < 0 || probability > 1) { 46 probability < 0 || probability > 1) {
46 DVLOG(1) << kAlternateProtocolHeader 47 DVLOG(1) << kAlternateProtocolHeader
47 << " header has unrecognizable probability: " 48 << " header has unrecognizable probability: "
48 << alternate_protocol_values[i]; 49 << alternate_protocol_values[i];
49 is_valid = false; 50 is_valid = false;
50 break; 51 break;
51 } 52 }
52 continue; 53 continue;
53 } 54 }
54 55
55 std::vector<std::string> port_protocol_vector; 56 std::vector<base::StringPiece> port_protocol_vector =
56 base::SplitString(alternate_protocol_str, ':', &port_protocol_vector); 57 base::SplitStringPiece(alternate_protocol_str, ":",
58 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
57 if (port_protocol_vector.size() != 2) { 59 if (port_protocol_vector.size() != 2) {
58 DVLOG(1) << kAlternateProtocolHeader 60 DVLOG(1) << kAlternateProtocolHeader
59 << " header has too many tokens: " 61 << " header has too many tokens: "
60 << alternate_protocol_str; 62 << alternate_protocol_str;
61 is_valid = false; 63 is_valid = false;
62 break; 64 break;
63 } 65 }
64 66
65 if (!base::StringToInt(port_protocol_vector[0], &port) || 67 if (!base::StringToInt(port_protocol_vector[0], &port) ||
66 port == 0 || !IsPortValid(port)) { 68 port == 0 || !IsPortValid(port)) {
67 DVLOG(1) << kAlternateProtocolHeader 69 DVLOG(1) << kAlternateProtocolHeader
68 << " header has unrecognizable port: " 70 << " header has unrecognizable port: "
69 << port_protocol_vector[0]; 71 << port_protocol_vector[0];
70 is_valid = false; 72 is_valid = false;
71 break; 73 break;
72 } 74 }
73 75
74 protocol = AlternateProtocolFromString(port_protocol_vector[1]); 76 protocol = AlternateProtocolFromString(port_protocol_vector[1].as_string());
75 77
76 if (IsAlternateProtocolValid(protocol) && 78 if (IsAlternateProtocolValid(protocol) &&
77 !session.IsProtocolEnabled(protocol)) { 79 !session.IsProtocolEnabled(protocol)) {
78 DVLOG(1) << kAlternateProtocolHeader 80 DVLOG(1) << kAlternateProtocolHeader
79 << " header has unrecognized protocol: " 81 << " header has unrecognized protocol: "
80 << port_protocol_vector[1]; 82 << port_protocol_vector[1];
81 is_valid = false; 83 is_valid = false;
82 break; 84 break;
83 } 85 }
84 } 86 }
(...skipping 23 matching lines...) Expand all
108 replacements.SetHost(endpoint->host().c_str(), 110 replacements.SetHost(endpoint->host().c_str(),
109 url::Component(0, endpoint->host().size())); 111 url::Component(0, endpoint->host().size()));
110 return url.ReplaceComponents(replacements); 112 return url.ReplaceComponents(replacements);
111 } 113 }
112 return url; 114 return url;
113 } 115 }
114 116
115 HttpStreamFactory::HttpStreamFactory() {} 117 HttpStreamFactory::HttpStreamFactory() {}
116 118
117 } // namespace net 119 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698