@@ -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.*;
|
||||
@@ -123,6 +124,9 @@ public class Socket extends Emitter {
|
||||
private Future pingIntervalTimer;
|
||||
private SSLContext sslContext;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
public Proxy proxy;
|
||||
public String proxyLogin;
|
||||
public String proxyPassword;
|
||||
|
||||
private ReadyState readyState;
|
||||
private ScheduledExecutorService heartbeatScheduler;
|
||||
@@ -200,6 +204,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.proxy = opts.proxy;
|
||||
this.proxyLogin = opts.proxyLogin;
|
||||
this.proxyPassword = opts.proxyPassword;
|
||||
}
|
||||
|
||||
public static void setDefaultSSLContext(SSLContext sslContext) {
|
||||
@@ -266,6 +273,9 @@ public class Socket extends Emitter {
|
||||
opts.policyPort = this.policyPort;
|
||||
opts.socket = this;
|
||||
opts.hostnameVerifier = this.hostnameVerifier;
|
||||
opts.proxy = this.proxy;
|
||||
opts.proxyLogin = this.proxyLogin;
|
||||
opts.proxyPassword = this.proxyPassword;
|
||||
|
||||
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,6 +44,9 @@ public abstract class Transport extends Emitter {
|
||||
protected SSLContext sslContext;
|
||||
protected Socket socket;
|
||||
protected HostnameVerifier hostnameVerifier;
|
||||
protected Proxy proxy;
|
||||
protected String proxyLogin;
|
||||
protected String proxyPassword;
|
||||
|
||||
protected ReadyState readyState;
|
||||
|
||||
@@ -57,6 +61,9 @@ public abstract class Transport extends Emitter {
|
||||
this.sslContext = opts.sslContext;
|
||||
this.socket = opts.socket;
|
||||
this.hostnameVerifier = opts.hostnameVerifier;
|
||||
this.proxy = opts.proxy;
|
||||
this.proxyLogin = opts.proxyLogin;
|
||||
this.proxyPassword = opts.proxyPassword;
|
||||
}
|
||||
|
||||
protected Transport onError(String msg, Exception desc) {
|
||||
@@ -152,5 +159,8 @@ public abstract class Transport extends Emitter {
|
||||
public SSLContext sslContext;
|
||||
public HostnameVerifier hostnameVerifier;
|
||||
protected Socket socket;
|
||||
public Proxy proxy;
|
||||
public String proxyLogin;
|
||||
public String proxyPassword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ package io.socket.engineio.client.transports;
|
||||
|
||||
|
||||
import io.socket.emitter.Emitter;
|
||||
import io.socket.thread.EventThread;
|
||||
import io.socket.engineio.client.Transport;
|
||||
import io.socket.thread.EventThread;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
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.*;
|
||||
@@ -34,6 +35,7 @@ public class PollingXHR extends Polling {
|
||||
opts.uri = this.uri();
|
||||
opts.sslContext = this.sslContext;
|
||||
opts.hostnameVerifier = this.hostnameVerifier;
|
||||
opts.proxy = this.proxy;
|
||||
|
||||
Request req = new Request(opts);
|
||||
|
||||
@@ -144,6 +146,7 @@ public class PollingXHR extends Polling {
|
||||
private SSLContext sslContext;
|
||||
private HttpURLConnection xhr;
|
||||
private HostnameVerifier hostnameVerifier;
|
||||
private Proxy proxy;
|
||||
|
||||
public Request(Options opts) {
|
||||
this.method = opts.method != null ? opts.method : "GET";
|
||||
@@ -151,6 +154,7 @@ public class PollingXHR extends Polling {
|
||||
this.data = opts.data;
|
||||
this.sslContext = opts.sslContext;
|
||||
this.hostnameVerifier = opts.hostnameVerifier;
|
||||
this.proxy = opts.proxy;
|
||||
}
|
||||
|
||||
public void create() {
|
||||
@@ -158,7 +162,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);
|
||||
xhr = (HttpURLConnection)url.openConnection();
|
||||
xhr = proxy != null ? (HttpURLConnection) url.openConnection(proxy)
|
||||
: (HttpURLConnection) url.openConnection();
|
||||
xhr.setRequestMethod(this.method);
|
||||
} catch (IOException e) {
|
||||
this.onError(e);
|
||||
@@ -313,6 +318,7 @@ public class PollingXHR extends Polling {
|
||||
public byte[] data;
|
||||
public SSLContext sslContext;
|
||||
public HostnameVerifier hostnameVerifier;
|
||||
public Proxy proxy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,7 @@ import io.socket.parseqs.ParseQS;
|
||||
import io.socket.thread.EventThread;
|
||||
import io.socket.utf8.UTF8Exception;
|
||||
import io.socket.yeast.Yeast;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.*;
|
||||
import okhttp3.ws.WebSocketCall;
|
||||
import okhttp3.ws.WebSocketListener;
|
||||
import okio.Buffer;
|
||||
@@ -61,6 +57,21 @@ public class WebSocket extends Transport {
|
||||
if (this.hostnameVerifier != null) {
|
||||
clientBuilder.hostnameVerifier(this.hostnameVerifier);
|
||||
}
|
||||
if (proxy != null) {
|
||||
clientBuilder.proxy(proxy);
|
||||
}
|
||||
if (proxyLogin != null && !proxyLogin.isEmpty()) {
|
||||
final String credentials = Credentials.basic(proxyLogin, proxyPassword);
|
||||
|
||||
clientBuilder.proxyAuthenticator(new Authenticator() {
|
||||
@Override
|
||||
public Request authenticate(Route route, Response response) throws IOException {
|
||||
return response.request().newBuilder()
|
||||
.header("Proxy-Authorization", credentials)
|
||||
.build();
|
||||
}
|
||||
});
|
||||
}
|
||||
Request.Builder builder = new Request.Builder().url(uri());
|
||||
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
|
||||
for (String v : entry.getValue()) {
|
||||
|
||||
Reference in New Issue
Block a user