diff options
-rw-r--r-- | net/proxy/proxy_info.h | 9 | ||||
-rw-r--r-- | net/proxy/proxy_server.cc | 10 | ||||
-rw-r--r-- | net/proxy/proxy_server.h | 6 | ||||
-rw-r--r-- | net/proxy/proxy_server_unittest.cc | 39 |
4 files changed, 62 insertions, 2 deletions
diff --git a/net/proxy/proxy_info.h b/net/proxy/proxy_info.h index ec5d05a..2531c6d 100644 --- a/net/proxy/proxy_info.h +++ b/net/proxy/proxy_info.h @@ -50,7 +50,14 @@ class ProxyInfo { return proxy_list_.Get().is_direct(); } - // Returns true if the first valid proxy server is a http proxy. + // Returns true if the first valid proxy server is an https proxy. + bool is_https() const { + if (is_empty()) + return false; + return proxy_server().is_https(); + } + + // Returns true if the first valid proxy server is an http proxy. bool is_http() const { if (is_empty()) return false; diff --git a/net/proxy/proxy_server.cc b/net/proxy/proxy_server.cc index ba45ff2..b78c347 100644 --- a/net/proxy/proxy_server.cc +++ b/net/proxy/proxy_server.cc @@ -34,6 +34,8 @@ ProxyServer::Scheme GetSchemeFromPacType(std::string::const_iterator begin, return ProxyServer::SCHEME_SOCKS5; if (LowerCaseEqualsASCII(begin, end, "direct")) return ProxyServer::SCHEME_DIRECT; + if (LowerCaseEqualsASCII(begin, end, "https")) + return ProxyServer::SCHEME_HTTPS; return ProxyServer::SCHEME_INVALID; } @@ -53,6 +55,8 @@ ProxyServer::Scheme GetSchemeFromURI(std::string::const_iterator begin, return ProxyServer::SCHEME_SOCKS5; if (LowerCaseEqualsASCII(begin, end, "direct")) return ProxyServer::SCHEME_DIRECT; + if (LowerCaseEqualsASCII(begin, end, "https")) + return ProxyServer::SCHEME_HTTPS; return ProxyServer::SCHEME_INVALID; } @@ -132,6 +136,8 @@ std::string ProxyServer::ToURI() const { return std::string("socks4://") + host_and_port(); case SCHEME_SOCKS5: return std::string("socks5://") + host_and_port(); + case SCHEME_HTTPS: + return std::string("https://") + host_and_port(); default: // Got called with an invalid scheme. NOTREACHED(); @@ -180,6 +186,8 @@ std::string ProxyServer::ToPacString() const { return std::string("SOCKS ") + host_and_port(); case SCHEME_SOCKS5: return std::string("SOCKS5 ") + host_and_port(); + case SCHEME_HTTPS: + return std::string("HTTPS ") + host_and_port(); default: // Got called with an invalid scheme. NOTREACHED(); @@ -195,6 +203,8 @@ int ProxyServer::GetDefaultPortForScheme(Scheme scheme) { case SCHEME_SOCKS4: case SCHEME_SOCKS5: return 1080; + case SCHEME_HTTPS: + return 443; default: return -1; } diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h index 6992e3e..3d5593c 100644 --- a/net/proxy/proxy_server.h +++ b/net/proxy/proxy_server.h @@ -29,6 +29,7 @@ class ProxyServer { SCHEME_HTTP = 1 << 2, SCHEME_SOCKS4 = 1 << 3, SCHEME_SOCKS5 = 1 << 4, + SCHEME_HTTPS = 1 << 5, }; // Default copy-constructor and assignment operator are OK! @@ -52,6 +53,9 @@ class ProxyServer { // Returns true if this ProxyServer is an HTTP proxy. bool is_http() const { return scheme_ == SCHEME_HTTP; } + // Returns true if this ProxyServer is an HTTPS proxy. + bool is_https() const { return scheme_ == SCHEME_HTTPS; } + // Returns true if this ProxyServer is a SOCKS proxy. bool is_socks() const { return scheme_ == SCHEME_SOCKS4 || scheme_ == SCHEME_SOCKS5; @@ -87,6 +91,7 @@ class ProxyServer { // "socks4://foopy" {scheme=SOCKS4, host="foopy", port=1080} // "socks5://foopy" {scheme=SOCKS5, host="foopy", port=1080} // "http://foopy:17" {scheme=HTTP, host="foopy", port=17} + // "https://foopy:17" {scheme=HTTPS, host="foopy", port=17} // "direct://" {scheme=DIRECT} // "foopy:X" INVALID -- bad port. static ProxyServer FromURI(const std::string& uri, Scheme default_scheme); @@ -108,6 +113,7 @@ class ProxyServer { // "PROXY foopy:19" {scheme=HTTP, host="foopy", port=19} // "DIRECT" {scheme=DIRECT} // "SOCKS5 foopy" {scheme=SOCKS5, host="foopy", port=1080} + // "HTTPS foopy:123" {scheme=HTTPS, host="foopy", port=123} // "BLAH xxx:xx" INVALID static ProxyServer FromPacString(const std::string& pac_string); static ProxyServer FromPacString(std::string::const_iterator pac_string_begin, diff --git a/net/proxy/proxy_server_unittest.cc b/net/proxy/proxy_server_unittest.cc index 0b06152..f91ad66 100644 --- a/net/proxy/proxy_server_unittest.cc +++ b/net/proxy/proxy_server_unittest.cc @@ -145,6 +145,35 @@ TEST(ProxyServerTest, FromURI) { "foopy:10", "SOCKS foopy:10" }, + + // HTTPS proxy URIs: + { + "https://foopy", // No port + "https://foopy:443", + net::ProxyServer::SCHEME_HTTPS, + "foopy", + 443, + "foopy:443", + "HTTPS foopy:443" + }, + { + "https://foopy:10", // Non-standard port + "https://foopy:10", + net::ProxyServer::SCHEME_HTTPS, + "foopy", + 10, + "foopy:10", + "HTTPS foopy:10" + }, + { + "https://1.2.3.4:10", // IP Address + "https://1.2.3.4:10", + net::ProxyServer::SCHEME_HTTPS, + "1.2.3.4", + 10, + "1.2.3.4:10", + "HTTPS 1.2.3.4:10" + }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { @@ -189,7 +218,6 @@ TEST(ProxyServerTest, Invalid) { "direct://xyz", // direct is not allowed a host/port. "http:/", // ambiguous, but will fail because of bad port. "http:", // ambiguous, but will fail because of bad port. - "https://blah", // "https" is not a valid proxy scheme. }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { @@ -259,6 +287,14 @@ TEST(ProxyServerTest, FromPACString) { " direct ", "direct://", }, + { + "https foopy", + "https://foopy:443", + }, + { + "https foopy:10", + "https://foopy:10", + }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { @@ -272,6 +308,7 @@ TEST(ProxyServerTest, FromPACString) { TEST(ProxyServerTest, FromPACStringInvalid) { const char* tests[] = { "PROXY", // missing host/port. + "HTTPS", // missing host/port. "SOCKS", // missing host/port. "DIRECT foopy:10", // direct cannot have host/port. }; |