Add proper support for http connect proxy on android
@@ -147,6 +147,25 @@ public class ProxySettings {
*/
public Socket getSocket(String protocol, String hostname, int port) throws IOException, URISyntaxException {
Proxy p = getProxy(protocol, hostname, port);
+
+ if (isAndroid() && p.type() == Proxy.Type.HTTP) {
+ LOG.debug("Replacing proxy implementation for Android system.");
+ SocketAddress sa = p.address();
+ if (sa instanceof InetSocketAddress) {
+ InetSocketAddress isa = (InetSocketAddress) sa;
+ String phost = isa.getHostString();
+ int pport = isa.getPort();
+ HttpConnectProxy hcp = new HttpConnectProxy("HTTP", false, phost, pport, null, null);
+ p = hcp;
+ }
+ }
+
+ if (p instanceof HttpConnectProxy) {
+ LOG.debug("Using custom HttpConnectProxy to obtain socket.");
+ HttpConnectProxy hcp = (HttpConnectProxy) p;
+ return hcp.getSocket(hostname, port);
+ } else {
+ LOG.debug("Using proxy ({}) to obtain socket.", p.type());
Socket sock = new Socket(p);
SocketAddress addr;
if (p.type() == Proxy.Type.DIRECT) {
@@ -160,5 +179,6 @@ public class ProxySettings {
sock.connect(addr, 60 * 1000);
return sock;
}
+ }
}
