提交 1c32c4eb 编写于 作者: K khazra

5001942: Missings SOCKS support for direct connections

Summary: Add support for socksNonProxyHosts
Reviewed-by: chegar, khazra
Contributed-by: NChristos Zoulas <christos@zoulas.com>
上级 294fb235
...@@ -124,6 +124,7 @@ public class DefaultProxySelector extends ProxySelector { ...@@ -124,6 +124,7 @@ public class DefaultProxySelector extends ProxySelector {
final String defaultVal; final String defaultVal;
static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null, defStringVal); static NonProxyInfo ftpNonProxyInfo = new NonProxyInfo("ftp.nonProxyHosts", null, null, defStringVal);
static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null, defStringVal); static NonProxyInfo httpNonProxyInfo = new NonProxyInfo("http.nonProxyHosts", null, null, defStringVal);
static NonProxyInfo socksNonProxyInfo = new NonProxyInfo("socksNonProxyHosts", null, null, defStringVal);
NonProxyInfo(String p, String s, RegexpPool pool, String d) { NonProxyInfo(String p, String s, RegexpPool pool, String d) {
property = p; property = p;
...@@ -186,6 +187,8 @@ public class DefaultProxySelector extends ProxySelector { ...@@ -186,6 +187,8 @@ public class DefaultProxySelector extends ProxySelector {
pinfo = NonProxyInfo.httpNonProxyInfo; pinfo = NonProxyInfo.httpNonProxyInfo;
} else if ("ftp".equalsIgnoreCase(protocol)) { } else if ("ftp".equalsIgnoreCase(protocol)) {
pinfo = NonProxyInfo.ftpNonProxyInfo; pinfo = NonProxyInfo.ftpNonProxyInfo;
} else if ("socket".equalsIgnoreCase(protocol)) {
pinfo = NonProxyInfo.socksNonProxyInfo;
} }
/** /**
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6964547 * @bug 6964547 5001942
* @run main/othervm SocksProxyVersion * @run main/othervm SocksProxyVersion
* @summary test socksProxyVersion system property * @summary test socksProxyVersion system property
*/ */
...@@ -34,6 +34,7 @@ import java.net.Socket; ...@@ -34,6 +34,7 @@ import java.net.Socket;
import java.net.SocketException; import java.net.SocketException;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
public class SocksProxyVersion implements Runnable { public class SocksProxyVersion implements Runnable {
final ServerSocket ss; final ServerSocket ss;
...@@ -56,13 +57,19 @@ public class SocksProxyVersion implements Runnable { ...@@ -56,13 +57,19 @@ public class SocksProxyVersion implements Runnable {
Thread serverThread = new Thread(this); Thread serverThread = new Thread(this);
serverThread.start(); serverThread.start();
System.setProperty("socksProxyHost", "localhost"); /*
* Retreving the IP Address of the machine
* since "localhost" is bypassed as a non-proxy host
*/
String addr = InetAddress.getLocalHost().getHostAddress();
System.setProperty("socksProxyHost", addr);
System.setProperty("socksProxyPort", Integer.toString(port)); System.setProperty("socksProxyPort", Integer.toString(port));
// SOCKS V4 // SOCKS V4
System.setProperty("socksProxyVersion", Integer.toString(4)); System.setProperty("socksProxyVersion", Integer.toString(4));
try (Socket s = new Socket()) { try (Socket s = new Socket()) {
s.connect(new InetSocketAddress("localhost", port)); s.connect(new InetSocketAddress(addr, port));
} catch (SocketException e) { } catch (SocketException e) {
// java.net.SocketException: Malformed reply from SOCKS server // java.net.SocketException: Malformed reply from SOCKS server
// This exception is OK, since the "server" does not implement // This exception is OK, since the "server" does not implement
...@@ -72,7 +79,7 @@ public class SocksProxyVersion implements Runnable { ...@@ -72,7 +79,7 @@ public class SocksProxyVersion implements Runnable {
// SOCKS V5 // SOCKS V5
System.setProperty("socksProxyVersion", Integer.toString(5)); System.setProperty("socksProxyVersion", Integer.toString(5));
try (Socket s = new Socket()) { try (Socket s = new Socket()) {
s.connect(new InetSocketAddress("localhost", port)); s.connect(new InetSocketAddress(addr, port));
} catch (SocketException e) { /* OK */ } } catch (SocketException e) { /* OK */ }
serverThread.join(); serverThread.join();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册