OLD | NEW |
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/string_tokenizer.h" | 9 #include "base/string_tokenizer.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const std::string::size_type len = host.size(); | 65 const std::string::size_type len = host.size(); |
66 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') | 66 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') |
67 return host.substr(1, len - 2); | 67 return host.substr(1, len - 2); |
68 return host; | 68 return host; |
69 } | 69 } |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) | 73 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) |
74 : scheme_(scheme), host_port_pair_(host_port_pair) { | 74 : scheme_(scheme), host_port_pair_(host_port_pair) { |
| 75 if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) { |
| 76 // |host_port_pair| isn't relevant for these special schemes, so none should |
| 77 // have been specified. It is important for this to be consistent since we |
| 78 // do raw field comparisons in the equality and comparison functions. |
| 79 DCHECK(host_port_pair.Equals(HostPortPair())); |
| 80 host_port_pair_ = HostPortPair(); |
| 81 } |
75 } | 82 } |
76 | 83 |
77 const HostPortPair& ProxyServer::host_port_pair() const { | 84 const HostPortPair& ProxyServer::host_port_pair() const { |
78 // Doesn't make sense to call this if the URI scheme doesn't | 85 // Doesn't make sense to call this if the URI scheme doesn't |
79 // have concept of a host. | 86 // have concept of a host. |
80 DCHECK(is_valid() && !is_direct()); | 87 DCHECK(is_valid() && !is_direct()); |
81 return host_port_pair_; | 88 return host_port_pair_; |
82 } | 89 } |
83 | 90 |
84 // static | 91 // static |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Scheme scheme, | 208 Scheme scheme, |
202 std::string::const_iterator begin, | 209 std::string::const_iterator begin, |
203 std::string::const_iterator end) { | 210 std::string::const_iterator end) { |
204 | 211 |
205 // Trim leading/trailing space. | 212 // Trim leading/trailing space. |
206 HttpUtil::TrimLWS(&begin, &end); | 213 HttpUtil::TrimLWS(&begin, &end); |
207 | 214 |
208 if (scheme == SCHEME_DIRECT && begin != end) | 215 if (scheme == SCHEME_DIRECT && begin != end) |
209 return ProxyServer(); // Invalid -- DIRECT cannot have a host/port. | 216 return ProxyServer(); // Invalid -- DIRECT cannot have a host/port. |
210 | 217 |
211 std::string host; | 218 HostPortPair host_port_pair; |
212 int port = -1; | |
213 | 219 |
214 if (scheme != SCHEME_INVALID && scheme != SCHEME_DIRECT) { | 220 if (scheme != SCHEME_INVALID && scheme != SCHEME_DIRECT) { |
| 221 std::string host; |
| 222 int port = -1; |
215 // If the scheme has a host/port, parse it. | 223 // If the scheme has a host/port, parse it. |
216 bool ok = net::ParseHostAndPort(begin, end, &host, &port); | 224 bool ok = net::ParseHostAndPort(begin, end, &host, &port); |
217 if (!ok) | 225 if (!ok) |
218 return ProxyServer(); // Invalid -- failed parsing <host>[":"<port>] | 226 return ProxyServer(); // Invalid -- failed parsing <host>[":"<port>] |
| 227 |
| 228 // Choose a default port number if none was given. |
| 229 if (port == -1) |
| 230 port = GetDefaultPortForScheme(scheme); |
| 231 |
| 232 host_port_pair = HostPortPair(HostNoBrackets(host), port); |
219 } | 233 } |
220 | 234 |
221 // Choose a default port number if none was given. | 235 return ProxyServer(scheme, host_port_pair); |
222 if (port == -1) | |
223 port = GetDefaultPortForScheme(scheme); | |
224 | |
225 return ProxyServer(scheme, HostPortPair(HostNoBrackets(host), port)); | |
226 } | 236 } |
227 | 237 |
228 } // namespace net | 238 } // namespace net |
OLD | NEW |