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

Side by Side Diff: net/proxy/proxy_server.cc

Issue 602973002: Change ParseHostAndPort() to not include brackets around IPv6 literals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment Created 6 years, 2 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 | « net/proxy/proxy_bypass_rules.cc ('k') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/proxy/proxy_server.h" 5 #include "net/proxy/proxy_server.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "net/base/net_util.h" 10 #include "net/base/net_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return ProxyServer::SCHEME_SOCKS5; 57 return ProxyServer::SCHEME_SOCKS5;
58 if (LowerCaseEqualsASCII(begin, end, "direct")) 58 if (LowerCaseEqualsASCII(begin, end, "direct"))
59 return ProxyServer::SCHEME_DIRECT; 59 return ProxyServer::SCHEME_DIRECT;
60 if (LowerCaseEqualsASCII(begin, end, "https")) 60 if (LowerCaseEqualsASCII(begin, end, "https"))
61 return ProxyServer::SCHEME_HTTPS; 61 return ProxyServer::SCHEME_HTTPS;
62 if (LowerCaseEqualsASCII(begin, end, "quic")) 62 if (LowerCaseEqualsASCII(begin, end, "quic"))
63 return ProxyServer::SCHEME_QUIC; 63 return ProxyServer::SCHEME_QUIC;
64 return ProxyServer::SCHEME_INVALID; 64 return ProxyServer::SCHEME_INVALID;
65 } 65 }
66 66
67 std::string HostNoBrackets(const std::string& host) {
68 // Remove brackets from an RFC 2732-style IPv6 literal address.
69 const std::string::size_type len = host.size();
70 if (len >= 2 && host[0] == '[' && host[len - 1] == ']')
71 return host.substr(1, len - 2);
72 return host;
73 }
74
75 } // namespace 67 } // namespace
76 68
77 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) 69 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair)
78 : scheme_(scheme), host_port_pair_(host_port_pair) { 70 : scheme_(scheme), host_port_pair_(host_port_pair) {
79 if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) { 71 if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) {
80 // |host_port_pair| isn't relevant for these special schemes, so none should 72 // |host_port_pair| isn't relevant for these special schemes, so none should
81 // have been specified. It is important for this to be consistent since we 73 // have been specified. It is important for this to be consistent since we
82 // do raw field comparisons in the equality and comparison functions. 74 // do raw field comparisons in the equality and comparison functions.
83 DCHECK(host_port_pair.Equals(HostPortPair())); 75 DCHECK(host_port_pair.Equals(HostPortPair()));
84 host_port_pair_ = HostPortPair(); 76 host_port_pair_ = HostPortPair();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 int port = -1; 231 int port = -1;
240 // If the scheme has a host/port, parse it. 232 // If the scheme has a host/port, parse it.
241 bool ok = net::ParseHostAndPort(begin, end, &host, &port); 233 bool ok = net::ParseHostAndPort(begin, end, &host, &port);
242 if (!ok) 234 if (!ok)
243 return ProxyServer(); // Invalid -- failed parsing <host>[":"<port>] 235 return ProxyServer(); // Invalid -- failed parsing <host>[":"<port>]
244 236
245 // Choose a default port number if none was given. 237 // Choose a default port number if none was given.
246 if (port == -1) 238 if (port == -1)
247 port = GetDefaultPortForScheme(scheme); 239 port = GetDefaultPortForScheme(scheme);
248 240
249 host_port_pair = HostPortPair(HostNoBrackets(host), port); 241 host_port_pair = HostPortPair(host, port);
250 } 242 }
251 243
252 return ProxyServer(scheme, host_port_pair); 244 return ProxyServer(scheme, host_port_pair);
253 } 245 }
254 246
255 } // namespace net 247 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_bypass_rules.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698