Simplify API: remove HttpConnectionProvider
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package io.socket.engineio.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public interface HttpConnectionProvider {
|
||||
HttpURLConnection openConnection(URL url) throws IOException;
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.json.JSONException;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.Proxy;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.*;
|
||||
@@ -128,11 +129,9 @@ public class Socket extends Emitter {
|
||||
private Future pingIntervalTimer;
|
||||
private SSLContext sslContext;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
public String proxyHost;
|
||||
public int proxyPort = -1;
|
||||
public Proxy proxy;
|
||||
public String proxyLogin;
|
||||
public String proxyPassword;
|
||||
private HttpConnectionProvider httpConnectionProvider;
|
||||
|
||||
private ReadyState readyState;
|
||||
private ScheduledExecutorService heartbeatScheduler;
|
||||
@@ -210,11 +209,9 @@ public class Socket extends Emitter {
|
||||
this.policyPort = opts.policyPort != 0 ? opts.policyPort : 843;
|
||||
this.rememberUpgrade = opts.rememberUpgrade;
|
||||
this.hostnameVerifier = opts.hostnameVerifier != null ? opts.hostnameVerifier : defaultHostnameVerifier;
|
||||
this.proxyHost = opts.proxyHost;
|
||||
this.proxyPort = opts.proxyPort;
|
||||
this.proxy = opts.proxy;
|
||||
this.proxyLogin = opts.proxyLogin;
|
||||
this.proxyPassword = opts.proxyPassword;
|
||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
||||
}
|
||||
|
||||
public static void setDefaultSSLContext(SSLContext sslContext) {
|
||||
@@ -281,11 +278,9 @@ public class Socket extends Emitter {
|
||||
opts.policyPort = this.policyPort;
|
||||
opts.socket = this;
|
||||
opts.hostnameVerifier = this.hostnameVerifier;
|
||||
opts.proxyHost = this.proxyHost;
|
||||
opts.proxyPort = this.proxyPort;
|
||||
opts.proxy = this.proxy;
|
||||
opts.proxyLogin = this.proxyLogin;
|
||||
opts.proxyPassword = this.proxyPassword;
|
||||
opts.httpConnectionProvider = this.httpConnectionProvider;
|
||||
|
||||
Transport transport;
|
||||
if (WebSocket.NAME.equals(name)) {
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.socket.utf8.UTF8Exception;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.Proxy;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Transport extends Emitter {
|
||||
@@ -43,11 +44,9 @@ public abstract class Transport extends Emitter {
|
||||
protected SSLContext sslContext;
|
||||
protected Socket socket;
|
||||
protected HostnameVerifier hostnameVerifier;
|
||||
protected String proxyHost;
|
||||
protected int proxyPort;
|
||||
protected Proxy proxy;
|
||||
protected String proxyLogin;
|
||||
protected String proxyPassword;
|
||||
protected HttpConnectionProvider httpConnectionProvider;
|
||||
|
||||
protected ReadyState readyState;
|
||||
|
||||
@@ -62,11 +61,9 @@ public abstract class Transport extends Emitter {
|
||||
this.sslContext = opts.sslContext;
|
||||
this.socket = opts.socket;
|
||||
this.hostnameVerifier = opts.hostnameVerifier;
|
||||
this.proxyHost = opts.proxyHost;
|
||||
this.proxyPort = opts.proxyPort;
|
||||
this.proxy = opts.proxy;
|
||||
this.proxyLogin = opts.proxyLogin;
|
||||
this.proxyPassword = opts.proxyPassword;
|
||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
||||
}
|
||||
|
||||
protected Transport onError(String msg, Exception desc) {
|
||||
@@ -162,10 +159,8 @@ public abstract class Transport extends Emitter {
|
||||
public SSLContext sslContext;
|
||||
public HostnameVerifier hostnameVerifier;
|
||||
protected Socket socket;
|
||||
public String proxyHost;
|
||||
public int proxyPort = -1;
|
||||
public Proxy proxy;
|
||||
public String proxyLogin;
|
||||
public String proxyPassword;
|
||||
public HttpConnectionProvider httpConnectionProvider;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.socket.engineio.client.transports;
|
||||
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import io.socket.engineio.client.HttpConnectionProvider;
|
||||
import io.socket.engineio.client.Transport;
|
||||
import io.socket.thread.EventThread;
|
||||
|
||||
@@ -11,6 +10,7 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
@@ -38,7 +38,7 @@ public class PollingXHR extends Polling {
|
||||
opts.uri = this.uri();
|
||||
opts.sslContext = this.sslContext;
|
||||
opts.hostnameVerifier = this.hostnameVerifier;
|
||||
opts.httpConnectionProvider = this.httpConnectionProvider;
|
||||
opts.proxy = this.proxy;
|
||||
|
||||
Request req = new Request(opts);
|
||||
|
||||
@@ -151,7 +151,7 @@ public class PollingXHR extends Polling {
|
||||
private SSLContext sslContext;
|
||||
private HttpURLConnection xhr;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
private HttpConnectionProvider httpConnectionProvider;
|
||||
private Proxy proxy;
|
||||
|
||||
public Request(Options opts) {
|
||||
this.method = opts.method != null ? opts.method : "GET";
|
||||
@@ -159,7 +159,7 @@ public class PollingXHR extends Polling {
|
||||
this.data = opts.data;
|
||||
this.sslContext = opts.sslContext;
|
||||
this.hostnameVerifier = opts.hostnameVerifier;
|
||||
this.httpConnectionProvider = opts.httpConnectionProvider;
|
||||
this.proxy = opts.proxy;
|
||||
}
|
||||
|
||||
public void create() {
|
||||
@@ -167,12 +167,8 @@ public class PollingXHR extends Polling {
|
||||
try {
|
||||
logger.fine(String.format("xhr open %s: %s", this.method, this.uri));
|
||||
URL url = new URL(this.uri);
|
||||
if (httpConnectionProvider != null) {
|
||||
xhr = httpConnectionProvider.openConnection(url);
|
||||
}
|
||||
if (xhr == null) {
|
||||
xhr = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
xhr = proxy != null ? (HttpURLConnection) url.openConnection(proxy)
|
||||
: (HttpURLConnection) url.openConnection();
|
||||
xhr.setRequestMethod(this.method);
|
||||
} catch (IOException e) {
|
||||
this.onError(e);
|
||||
@@ -331,7 +327,7 @@ public class PollingXHR extends Polling {
|
||||
public byte[] data;
|
||||
public SSLContext sslContext;
|
||||
public HostnameVerifier hostnameVerifier;
|
||||
public HttpConnectionProvider httpConnectionProvider;
|
||||
public Proxy proxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ import okio.Buffer;
|
||||
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -59,8 +57,8 @@ public class WebSocket extends Transport {
|
||||
if (this.hostnameVerifier != null) {
|
||||
clientBuilder.hostnameVerifier(this.hostnameVerifier);
|
||||
}
|
||||
if (proxyHost != null && !proxyHost.isEmpty() && proxyPort >= 0) {
|
||||
clientBuilder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)));
|
||||
if (proxy != null) {
|
||||
clientBuilder.proxy(proxy);
|
||||
}
|
||||
if (proxyLogin != null && !proxyLogin.isEmpty()) {
|
||||
final String credentials = Credentials.basic(proxyLogin, proxyPassword);
|
||||
|
||||
Reference in New Issue
Block a user