| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
| 12 #include "net/http/http_util.h" | 12 #include "net/http/http_util.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // Parses the proxy type from a PAC string, to a ProxyServer::Scheme. | 18 // Parses the proxy type from a PAC string, to a ProxyServer::Scheme. |
| 19 // This mapping is case-insensitive. If no type could be matched | 19 // This mapping is case-insensitive. If no type could be matched |
| 20 // returns SCHEME_INVALID. | 20 // returns SCHEME_INVALID. |
| 21 ProxyServer::Scheme GetSchemeFromPacTypeInternal( | 21 ProxyServer::Scheme GetSchemeFromPacTypeInternal( |
| 22 std::string::const_iterator begin, | 22 std::string::const_iterator begin, |
| 23 std::string::const_iterator end) { | 23 std::string::const_iterator end) { |
| 24 if (LowerCaseEqualsASCII(begin, end, "proxy")) | 24 if (base::LowerCaseEqualsASCII(begin, end, "proxy")) |
| 25 return ProxyServer::SCHEME_HTTP; | 25 return ProxyServer::SCHEME_HTTP; |
| 26 if (LowerCaseEqualsASCII(begin, end, "socks")) { | 26 if (base::LowerCaseEqualsASCII(begin, end, "socks")) { |
| 27 // Default to v4 for compatibility. This is because the SOCKS4 vs SOCKS5 | 27 // Default to v4 for compatibility. This is because the SOCKS4 vs SOCKS5 |
| 28 // notation didn't originally exist, so if a client returns SOCKS they | 28 // notation didn't originally exist, so if a client returns SOCKS they |
| 29 // really meant SOCKS4. | 29 // really meant SOCKS4. |
| 30 return ProxyServer::SCHEME_SOCKS4; | 30 return ProxyServer::SCHEME_SOCKS4; |
| 31 } | 31 } |
| 32 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 32 if (base::LowerCaseEqualsASCII(begin, end, "socks4")) |
| 33 return ProxyServer::SCHEME_SOCKS4; | 33 return ProxyServer::SCHEME_SOCKS4; |
| 34 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 34 if (base::LowerCaseEqualsASCII(begin, end, "socks5")) |
| 35 return ProxyServer::SCHEME_SOCKS5; | 35 return ProxyServer::SCHEME_SOCKS5; |
| 36 if (LowerCaseEqualsASCII(begin, end, "direct")) | 36 if (base::LowerCaseEqualsASCII(begin, end, "direct")) |
| 37 return ProxyServer::SCHEME_DIRECT; | 37 return ProxyServer::SCHEME_DIRECT; |
| 38 if (LowerCaseEqualsASCII(begin, end, "https")) | 38 if (base::LowerCaseEqualsASCII(begin, end, "https")) |
| 39 return ProxyServer::SCHEME_HTTPS; | 39 return ProxyServer::SCHEME_HTTPS; |
| 40 if (LowerCaseEqualsASCII(begin, end, "quic")) | 40 if (base::LowerCaseEqualsASCII(begin, end, "quic")) |
| 41 return ProxyServer::SCHEME_QUIC; | 41 return ProxyServer::SCHEME_QUIC; |
| 42 | 42 |
| 43 return ProxyServer::SCHEME_INVALID; | 43 return ProxyServer::SCHEME_INVALID; |
| 44 } | 44 } |
| 45 | 45 |
| 46 // Parses the proxy scheme from a URL-like representation, to a | 46 // Parses the proxy scheme from a URL-like representation, to a |
| 47 // ProxyServer::Scheme. This corresponds with the values used in | 47 // ProxyServer::Scheme. This corresponds with the values used in |
| 48 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. | 48 // ProxyServer::ToURI(). If no type could be matched, returns SCHEME_INVALID. |
| 49 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, | 49 ProxyServer::Scheme GetSchemeFromURIInternal(std::string::const_iterator begin, |
| 50 std::string::const_iterator end) { | 50 std::string::const_iterator end) { |
| 51 if (LowerCaseEqualsASCII(begin, end, "http")) | 51 if (base::LowerCaseEqualsASCII(begin, end, "http")) |
| 52 return ProxyServer::SCHEME_HTTP; | 52 return ProxyServer::SCHEME_HTTP; |
| 53 if (LowerCaseEqualsASCII(begin, end, "socks4")) | 53 if (base::LowerCaseEqualsASCII(begin, end, "socks4")) |
| 54 return ProxyServer::SCHEME_SOCKS4; | 54 return ProxyServer::SCHEME_SOCKS4; |
| 55 if (LowerCaseEqualsASCII(begin, end, "socks")) | 55 if (base::LowerCaseEqualsASCII(begin, end, "socks")) |
| 56 return ProxyServer::SCHEME_SOCKS5; | 56 return ProxyServer::SCHEME_SOCKS5; |
| 57 if (LowerCaseEqualsASCII(begin, end, "socks5")) | 57 if (base::LowerCaseEqualsASCII(begin, end, "socks5")) |
| 58 return ProxyServer::SCHEME_SOCKS5; | 58 return ProxyServer::SCHEME_SOCKS5; |
| 59 if (LowerCaseEqualsASCII(begin, end, "direct")) | 59 if (base::LowerCaseEqualsASCII(begin, end, "direct")) |
| 60 return ProxyServer::SCHEME_DIRECT; | 60 return ProxyServer::SCHEME_DIRECT; |
| 61 if (LowerCaseEqualsASCII(begin, end, "https")) | 61 if (base::LowerCaseEqualsASCII(begin, end, "https")) |
| 62 return ProxyServer::SCHEME_HTTPS; | 62 return ProxyServer::SCHEME_HTTPS; |
| 63 if (LowerCaseEqualsASCII(begin, end, "quic")) | 63 if (base::LowerCaseEqualsASCII(begin, end, "quic")) |
| 64 return ProxyServer::SCHEME_QUIC; | 64 return ProxyServer::SCHEME_QUIC; |
| 65 return ProxyServer::SCHEME_INVALID; | 65 return ProxyServer::SCHEME_INVALID; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) | 70 ProxyServer::ProxyServer(Scheme scheme, const HostPortPair& host_port_pair) |
| 71 : scheme_(scheme), host_port_pair_(host_port_pair) { | 71 : scheme_(scheme), host_port_pair_(host_port_pair) { |
| 72 if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) { | 72 if (scheme_ == SCHEME_DIRECT || scheme_ == SCHEME_INVALID) { |
| 73 // |host_port_pair| isn't relevant for these special schemes, so none should | 73 // |host_port_pair| isn't relevant for these special schemes, so none should |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (port == -1) | 239 if (port == -1) |
| 240 port = GetDefaultPortForScheme(scheme); | 240 port = GetDefaultPortForScheme(scheme); |
| 241 | 241 |
| 242 host_port_pair = HostPortPair(host, static_cast<uint16>(port)); | 242 host_port_pair = HostPortPair(host, static_cast<uint16>(port)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 return ProxyServer(scheme, host_port_pair); | 245 return ProxyServer(scheme, host_port_pair); |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace net | 248 } // namespace net |
| OLD | NEW |