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/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 18 matching lines...) Expand all Loading... |
29 return ProxyServer::SCHEME_SOCKS4; | 29 return ProxyServer::SCHEME_SOCKS4; |
30 } | 30 } |
31 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 31 if (LowerCaseEqualsASCII(begin, end, "socks4")) |
32 return ProxyServer::SCHEME_SOCKS4; | 32 return ProxyServer::SCHEME_SOCKS4; |
33 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 33 if (LowerCaseEqualsASCII(begin, end, "socks5")) |
34 return ProxyServer::SCHEME_SOCKS5; | 34 return ProxyServer::SCHEME_SOCKS5; |
35 if (LowerCaseEqualsASCII(begin, end, "direct")) | 35 if (LowerCaseEqualsASCII(begin, end, "direct")) |
36 return ProxyServer::SCHEME_DIRECT; | 36 return ProxyServer::SCHEME_DIRECT; |
37 if (LowerCaseEqualsASCII(begin, end, "https")) | 37 if (LowerCaseEqualsASCII(begin, end, "https")) |
38 return ProxyServer::SCHEME_HTTPS; | 38 return ProxyServer::SCHEME_HTTPS; |
| 39 if (LowerCaseEqualsASCII(begin, end, "quic")) |
| 40 return ProxyServer::SCHEME_QUIC; |
39 | 41 |
40 return ProxyServer::SCHEME_INVALID; | 42 return ProxyServer::SCHEME_INVALID; |
41 } | 43 } |
42 | 44 |
43 // Parses the proxy scheme from a URL-like representation, to a | 45 // Parses the proxy scheme from a URL-like representation, to a |
44 // ProxyServer::Scheme. This corresponds with the values used in | 46 // ProxyServer::Scheme. This corresponds with the values used in |
45 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. | 47 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. |
46 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, | 48 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, |
47 std::string::const_iterator end) { | 49 std::string::const_iterator end) { |
48 if (LowerCaseEqualsASCII(begin, end, "http")) | 50 if (LowerCaseEqualsASCII(begin, end, "http")) |
49 return ProxyServer::SCHEME_HTTP; | 51 return ProxyServer::SCHEME_HTTP; |
50 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 52 if (LowerCaseEqualsASCII(begin, end, "socks4")) |
51 return ProxyServer::SCHEME_SOCKS4; | 53 return ProxyServer::SCHEME_SOCKS4; |
52 if (LowerCaseEqualsASCII(begin, end, "socks")) | 54 if (LowerCaseEqualsASCII(begin, end, "socks")) |
53 return ProxyServer::SCHEME_SOCKS5; | 55 return ProxyServer::SCHEME_SOCKS5; |
54 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 56 if (LowerCaseEqualsASCII(begin, end, "socks5")) |
55 return ProxyServer::SCHEME_SOCKS5; | 57 return ProxyServer::SCHEME_SOCKS5; |
56 if (LowerCaseEqualsASCII(begin, end, "direct")) | 58 if (LowerCaseEqualsASCII(begin, end, "direct")) |
57 return ProxyServer::SCHEME_DIRECT; | 59 return ProxyServer::SCHEME_DIRECT; |
58 if (LowerCaseEqualsASCII(begin, end, "https")) | 60 if (LowerCaseEqualsASCII(begin, end, "https")) |
59 return ProxyServer::SCHEME_HTTPS; | 61 return ProxyServer::SCHEME_HTTPS; |
| 62 if (LowerCaseEqualsASCII(begin, end, "quic")) |
| 63 return ProxyServer::SCHEME_QUIC; |
60 return ProxyServer::SCHEME_INVALID; | 64 return ProxyServer::SCHEME_INVALID; |
61 } | 65 } |
62 | 66 |
63 std::string HostNoBrackets(const std::string& host) { | 67 std::string HostNoBrackets(const std::string& host) { |
64 // Remove brackets from an RFC 2732-style IPv6 literal address. | 68 // Remove brackets from an RFC 2732-style IPv6 literal address. |
65 const std::string::size_type len = host.size(); | 69 const std::string::size_type len = host.size(); |
66 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') | 70 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') |
67 return host.substr(1, len - 2); | 71 return host.substr(1, len - 2); |
68 return host; | 72 return host; |
69 } | 73 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 return "direct://"; | 128 return "direct://"; |
125 case SCHEME_HTTP: | 129 case SCHEME_HTTP: |
126 // Leave off "http://" since it is our default scheme. | 130 // Leave off "http://" since it is our default scheme. |
127 return host_port_pair().ToString(); | 131 return host_port_pair().ToString(); |
128 case SCHEME_SOCKS4: | 132 case SCHEME_SOCKS4: |
129 return std::string("socks4://") + host_port_pair().ToString(); | 133 return std::string("socks4://") + host_port_pair().ToString(); |
130 case SCHEME_SOCKS5: | 134 case SCHEME_SOCKS5: |
131 return std::string("socks5://") + host_port_pair().ToString(); | 135 return std::string("socks5://") + host_port_pair().ToString(); |
132 case SCHEME_HTTPS: | 136 case SCHEME_HTTPS: |
133 return std::string("https://") + host_port_pair().ToString(); | 137 return std::string("https://") + host_port_pair().ToString(); |
| 138 case SCHEME_QUIC: |
| 139 return std::string("quic://") + host_port_pair().ToString(); |
134 default: | 140 default: |
135 // Got called with an invalid scheme. | 141 // Got called with an invalid scheme. |
136 NOTREACHED(); | 142 NOTREACHED(); |
137 return std::string(); | 143 return std::string(); |
138 } | 144 } |
139 } | 145 } |
140 | 146 |
141 // static | 147 // static |
142 ProxyServer ProxyServer::FromPacString(const std::string& pac_string) { | 148 ProxyServer ProxyServer::FromPacString(const std::string& pac_string) { |
143 return FromPacString(pac_string.begin(), pac_string.end()); | 149 return FromPacString(pac_string.begin(), pac_string.end()); |
(...skipping 30 matching lines...) Expand all Loading... |
174 return "DIRECT"; | 180 return "DIRECT"; |
175 case SCHEME_HTTP: | 181 case SCHEME_HTTP: |
176 return std::string("PROXY ") + host_port_pair().ToString(); | 182 return std::string("PROXY ") + host_port_pair().ToString(); |
177 case SCHEME_SOCKS4: | 183 case SCHEME_SOCKS4: |
178 // For compatibility send SOCKS instead of SOCKS4. | 184 // For compatibility send SOCKS instead of SOCKS4. |
179 return std::string("SOCKS ") + host_port_pair().ToString(); | 185 return std::string("SOCKS ") + host_port_pair().ToString(); |
180 case SCHEME_SOCKS5: | 186 case SCHEME_SOCKS5: |
181 return std::string("SOCKS5 ") + host_port_pair().ToString(); | 187 return std::string("SOCKS5 ") + host_port_pair().ToString(); |
182 case SCHEME_HTTPS: | 188 case SCHEME_HTTPS: |
183 return std::string("HTTPS ") + host_port_pair().ToString(); | 189 return std::string("HTTPS ") + host_port_pair().ToString(); |
| 190 case SCHEME_QUIC: |
| 191 return std::string("QUIC ") + host_port_pair().ToString(); |
184 default: | 192 default: |
185 // Got called with an invalid scheme. | 193 // Got called with an invalid scheme. |
186 NOTREACHED(); | 194 NOTREACHED(); |
187 return std::string(); | 195 return std::string(); |
188 } | 196 } |
189 } | 197 } |
190 | 198 |
191 // static | 199 // static |
192 int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { | 200 int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { |
193 switch (scheme) { | 201 switch (scheme) { |
194 case SCHEME_HTTP: | 202 case SCHEME_HTTP: |
195 return 80; | 203 return 80; |
196 case SCHEME_SOCKS4: | 204 case SCHEME_SOCKS4: |
197 case SCHEME_SOCKS5: | 205 case SCHEME_SOCKS5: |
198 return 1080; | 206 return 1080; |
199 case SCHEME_HTTPS: | 207 case SCHEME_HTTPS: |
| 208 case SCHEME_QUIC: |
200 return 443; | 209 return 443; |
201 default: | 210 case SCHEME_INVALID: |
202 return -1; | 211 case SCHEME_DIRECT: |
| 212 break; |
203 } | 213 } |
| 214 return -1; |
204 } | 215 } |
205 | 216 |
206 // static | 217 // static |
207 ProxyServer::Scheme ProxyServer::GetSchemeFromURI(const std::string& scheme) { | 218 ProxyServer::Scheme ProxyServer::GetSchemeFromURI(const std::string& scheme) { |
208 return GetSchemeFromURIInternal(scheme.begin(), scheme.end()); | 219 return GetSchemeFromURIInternal(scheme.begin(), scheme.end()); |
209 } | 220 } |
210 | 221 |
211 // TODO(bengr): Use |scheme_| to indicate that this is the data reduction proxy. | 222 // TODO(bengr): Use |scheme_| to indicate that this is the data reduction proxy. |
212 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 223 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
213 bool ProxyServer::isDataReductionProxy() const { | 224 bool ProxyServer::isDataReductionProxy() const { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (port == -1) | 266 if (port == -1) |
256 port = GetDefaultPortForScheme(scheme); | 267 port = GetDefaultPortForScheme(scheme); |
257 | 268 |
258 host_port_pair = HostPortPair(HostNoBrackets(host), port); | 269 host_port_pair = HostPortPair(HostNoBrackets(host), port); |
259 } | 270 } |
260 | 271 |
261 return ProxyServer(scheme, host_port_pair); | 272 return ProxyServer(scheme, host_port_pair); |
262 } | 273 } |
263 | 274 |
264 } // namespace net | 275 } // namespace net |
OLD | NEW |