Merge pull request #240 from Cosium/java.net.useSystemProxies

Usage of Proxy.NO_PROXY prevents -Djava.net.useSystemProxies=true from kicking in
This commit is contained in:
Michael Bayne
2021-04-05 07:29:42 -07:00
committed by GitHub
2 changed files with 16 additions and 4 deletions
@@ -32,7 +32,7 @@ import com.threerings.getdown.util.StreamUtil;
public class Connector { public class Connector {
/** The default connector uses no proxy. */ /** The default connector uses no proxy. */
public static final Connector DEFAULT = new Connector(Proxy.NO_PROXY); public static final Connector DEFAULT = new Connector();
/** Tracks the state of a connector. If it fails for proxy-related reasons, it may transition /** Tracks the state of a connector. If it fails for proxy-related reasons, it may transition
* to a need_proxy or need_proxy_auth state. */ * to a need_proxy or need_proxy_auth state. */
@@ -44,7 +44,14 @@ public class Connector {
/** The current state of this connector. */ /** The current state of this connector. */
public State state = State.ACTIVE; public State state = State.ACTIVE;
public Connector(){
this(null);
}
public Connector (Proxy proxy) { public Connector (Proxy proxy) {
if (proxy == Proxy.NO_PROXY){
throw new IllegalArgumentException("The passed Proxy cannot be " + Proxy.NO_PROXY + ". Use the empty constructor instead");
}
this.proxy = proxy; this.proxy = proxy;
} }
@@ -61,7 +68,12 @@ public class Connector {
public URLConnection open (URL url, int connectTimeout, int readTimeout) public URLConnection open (URL url, int connectTimeout, int readTimeout)
throws IOException throws IOException
{ {
URLConnection conn = url.openConnection(proxy); URLConnection conn;
if (proxy == null) {
conn = url.openConnection();
} else {
conn = url.openConnection(proxy);
}
// configure a connect timeout, if requested // configure a connect timeout, if requested
int ctimeout = connectTimeout > 0 ? connectTimeout : SysProps.connectTimeout(); int ctimeout = connectTimeout > 0 ? connectTimeout : SysProps.connectTimeout();
@@ -176,7 +188,7 @@ public class Connector {
* command line args that will be used to launch the app. * command line args that will be used to launch the app.
*/ */
public void addProxyArgs (List<String> args) { public void addProxyArgs (List<String> args) {
if (proxy.type() == Proxy.Type.HTTP && proxy.address() instanceof InetSocketAddress) { if (proxy != null && proxy.type() == Proxy.Type.HTTP && proxy.address() instanceof InetSocketAddress) {
InetSocketAddress proxyAddr = (InetSocketAddress) proxy.address(); InetSocketAddress proxyAddr = (InetSocketAddress) proxy.address();
String proxyHost = proxyAddr.getHostString(); String proxyHost = proxyAddr.getHostString();
int proxyPort = proxyAddr.getPort(); int proxyPort = proxyAddr.getPort();
@@ -216,7 +216,7 @@ public final class ProxyUtil {
if (StringUtil.isBlank(host)) { if (StringUtil.isBlank(host)) {
log.info("Using no proxy"); log.info("Using no proxy");
app.conn = new Connector(Proxy.NO_PROXY); app.conn = new Connector();
} else { } else {
int pp = StringUtil.isBlank(port) ? 80 : Integer.valueOf(port); int pp = StringUtil.isBlank(port) ? 80 : Integer.valueOf(port);
log.info("Using proxy", "host", host, "port", pp, "haveCreds", haveCreds); log.info("Using proxy", "host", host, "port", pp, "haveCreds", haveCreds);