Skip to content

Commit

Permalink
Fix SOCKS proxy settings not being returned (closes MarkusBernhardt#10)
Browse files Browse the repository at this point in the history
Although SOCKS proxy settings are detected correctly, the
ProtocolDispatchSelector tries to lookup a selector using the protocol
as the key, which doesn't work for SOCKS because "socks://" isn't part
of the URL.

The fix is to specify it as a fallback instead, so that it is
automatically used in the absence of a more protocol specific (e.g.
http) setting.
  • Loading branch information
OnixGH authored and Daniel Knoppel committed Jul 24, 2018
1 parent c20f9a5 commit 3977747
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.markusbernhardt.proxy.ProxySearchStrategy;
import com.github.markusbernhardt.proxy.search.browser.ie.IELocalByPassFilter;
import com.github.markusbernhardt.proxy.selector.fixed.FixedProxySelector;
import com.github.markusbernhardt.proxy.selector.fixed.FixedSocksSelector;
import com.github.markusbernhardt.proxy.selector.misc.ProtocolDispatchSelector;
import com.github.markusbernhardt.proxy.selector.whitelist.ProxyBypassListSelector;
import com.github.markusbernhardt.proxy.util.Logger;
Expand Down Expand Up @@ -131,8 +132,31 @@ protected ProtocolDispatchSelector buildProtocolDispatchSelector(Properties prop
addSelectorForProtocol(properties, "https", ps);
addSelectorForProtocol(properties, "ftp", ps);
addSelectorForProtocol(properties, "gopher", ps);
addSelectorForProtocol(properties, "socks", ps);

// these are the "default" settings, which may be overridden by "socks" (below)
addFallbackSelector(properties, ps);

// "socks" is a special case: it can be used as a fallback for the protocols above (e.g. http),
// so it must be specified as such (URLs won't specify socks:// that addSelectorForProtocol() would
// use as lookup key).
String socksProperties = properties.getProperty("socks");
if (socksProperties != null) {
String[] hostAndPort = socksProperties.split(":");
String host = "";
int port = 0;
if (hostAndPort.length > 0) {
host = hostAndPort[0];
}
if (hostAndPort.length > 1) {
try {
port = Integer.parseInt(hostAndPort[1]);
} catch (NumberFormatException e) {
Logger.log(CommonWindowsSearchStrategy.class, Logger.LogLevel.WARNING, "Cannot parse SOCKS proxy port {0}", hostAndPort[1]);
}
}
ps.setFallbackSelector(new FixedSocksSelector(host, port));
}

return ps;
}
}

0 comments on commit 3977747

Please sign in to comment.