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" |
11 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Parses the proxy type from a PAC string, to a ProxyServer::Scheme. | 17 // Parses the proxy type from a PAC string, to a ProxyServer::Scheme. |
18 // This mapping is case-insensitive. If no type could be matched | 18 // This mapping is case-insensitive. If no type could be matched |
19 // returns SCHEME_INVALID. | 19 // returns SCHEME_INVALID. |
20 ProxyServer::Scheme GetSchemeFromPacTypeInternal( | 20 ProxyServer::Scheme GetSchemeFromPacTypeInternal( |
21 std::string::const_iterator begin, | 21 std::string::const_iterator begin, |
22 std::string::const_iterator end) { | 22 std::string::const_iterator end) { |
23 if (LowerCaseEqualsASCII(begin, end, "proxy")) | 23 if (base::LowerCaseEqualsASCII(begin, end, "proxy")) |
24 return ProxyServer::SCHEME_HTTP; | 24 return ProxyServer::SCHEME_HTTP; |
25 if (LowerCaseEqualsASCII(begin, end, "socks")) { | 25 if (base::LowerCaseEqualsASCII(begin, end, "socks")) { |
26 // Default to v4 for compatibility. This is because the SOCKS4 vs SOCKS5 | 26 // Default to v4 for compatibility. This is because the SOCKS4 vs SOCKS5 |
27 // notation didn't originally exist, so if a client returns SOCKS they | 27 // notation didn't originally exist, so if a client returns SOCKS they |
28 // really meant SOCKS4. | 28 // really meant SOCKS4. |
29 return ProxyServer::SCHEME_SOCKS4; | 29 return ProxyServer::SCHEME_SOCKS4; |
30 } | 30 } |
31 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 31 if (base::LowerCaseEqualsASCII(begin, end, "socks4")) |
32 return ProxyServer::SCHEME_SOCKS4; | 32 return ProxyServer::SCHEME_SOCKS4; |
33 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 33 if (base::LowerCaseEqualsASCII(begin, end, "socks5")) |
34 return ProxyServer::SCHEME_SOCKS5; | 34 return ProxyServer::SCHEME_SOCKS5; |
35 if (LowerCaseEqualsASCII(begin, end, "direct")) | 35 if (base::LowerCaseEqualsASCII(begin, end, "direct")) |
36 return ProxyServer::SCHEME_DIRECT; | 36 return ProxyServer::SCHEME_DIRECT; |
37 if (LowerCaseEqualsASCII(begin, end, "https")) | 37 if (base::LowerCaseEqualsASCII(begin, end, "https")) |
38 return ProxyServer::SCHEME_HTTPS; | 38 return ProxyServer::SCHEME_HTTPS; |
39 if (LowerCaseEqualsASCII(begin, end, "quic")) | 39 if (base::LowerCaseEqualsASCII(begin, end, "quic")) |
40 return ProxyServer::SCHEME_QUIC; | 40 return ProxyServer::SCHEME_QUIC; |
41 | 41 |
42 return ProxyServer::SCHEME_INVALID; | 42 return ProxyServer::SCHEME_INVALID; |
43 } | 43 } |
44 | 44 |
45 // Parses the proxy scheme from a URL-like representation, to a | 45 // Parses the proxy scheme from a URL-like representation, to a |
46 // ProxyServer::Scheme. This corresponds with the values used in | 46 // ProxyServer::Scheme. This corresponds with the values used in |
47 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. | 47 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. |
48 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, | 48 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, |
49 std::string::const_iterator end) { | 49 std::string::const_iterator end) { |
50 if (LowerCaseEqualsASCII(begin, end, "http")) | 50 if (base::LowerCaseEqualsASCII(begin, end, "http")) |
51 return ProxyServer::SCHEME_HTTP; | 51 return ProxyServer::SCHEME_HTTP; |
52 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 52 if (base::LowerCaseEqualsASCII(begin, end, "socks4")) |
53 return ProxyServer::SCHEME_SOCKS4; | 53 return ProxyServer::SCHEME_SOCKS4; |
54 if (LowerCaseEqualsASCII(begin, end, "socks")) | 54 if (base::LowerCaseEqualsASCII(begin, end, "socks")) |
55 return ProxyServer::SCHEME_SOCKS5; | 55 return ProxyServer::SCHEME_SOCKS5; |
56 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 56 if (base::LowerCaseEqualsASCII(begin, end, "socks5")) |
57 return ProxyServer::SCHEME_SOCKS5; | 57 return ProxyServer::SCHEME_SOCKS5; |
58 if (LowerCaseEqualsASCII(begin, end, "direct")) | 58 if (base::LowerCaseEqualsASCII(begin, end, "direct")) |
59 return ProxyServer::SCHEME_DIRECT; | 59 return ProxyServer::SCHEME_DIRECT; |
60 if (LowerCaseEqualsASCII(begin, end, "https")) | 60 if (base::LowerCaseEqualsASCII(begin, end, "https")) |
61 return ProxyServer::SCHEME_HTTPS; | 61 return ProxyServer::SCHEME_HTTPS; |
62 if (LowerCaseEqualsASCII(begin, end, "quic")) | 62 if (base::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) { | 67 std::string HostNoBrackets(const std::string& host) { |
68 // Remove brackets from an RFC 2732-style IPv6 literal address. | 68 // Remove brackets from an RFC 2732-style IPv6 literal address. |
69 const std::string::size_type len = host.size(); | 69 const std::string::size_type len = host.size(); |
70 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') | 70 if (len >= 2 && host[0] == '[' && host[len - 1] == ']') |
71 return host.substr(1, len - 2); | 71 return host.substr(1, len - 2); |
72 return host; | 72 return host; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 if (port == -1) | 245 if (port == -1) |
246 port = GetDefaultPortForScheme(scheme); | 246 port = GetDefaultPortForScheme(scheme); |
247 | 247 |
248 host_port_pair = HostPortPair(HostNoBrackets(host), port); | 248 host_port_pair = HostPortPair(HostNoBrackets(host), port); |
249 } | 249 } |
250 | 250 |
251 return ProxyServer(scheme, host_port_pair); | 251 return ProxyServer(scheme, host_port_pair); |
252 } | 252 } |
253 | 253 |
254 } // namespace net | 254 } // namespace net |
OLD | NEW |