Skip to content

Commit a76e052

Browse files
authored
Merge pull request TooTallNate#1070 from marci4/Issue1058
2 parents 2a91fe2 + e1061ae commit a76e052

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

‎src/main/java/org/java_websocket/client/WebSocketClient.java‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,12 +461,16 @@ public void sendPing(){
461461
publicvoidrun(){
462462
InputStreamistream;
463463
try{
464-
booleanisNewSocket = false;
465-
if (socketFactory != null){
464+
booleanupgradeSocketToSSLSocket = false;
465+
// Prioritise a proxy over a socket factory and apply the socketfactory later
466+
if (proxy != Proxy.NO_PROXY){
467+
socket = newSocket(proxy);
468+
upgradeSocketToSSLSocket = true;
469+
} elseif (socketFactory != null){
466470
socket = socketFactory.createSocket();
467471
} elseif (socket == null){
468472
socket = newSocket(proxy);
469-
isNewSocket = true;
473+
upgradeSocketToSSLSocket = true;
470474
} elseif (socket.isClosed()){
471475
thrownewIOException();
472476
}
@@ -480,10 +484,17 @@ public void run(){
480484
}
481485

482486
// if the socket is set by others we don't apply any TLS wrapper
483-
if (isNewSocket && "wss".equals(uri.getScheme())){
484-
SSLContextsslContext = SSLContext.getInstance("TLSv1.2");
485-
sslContext.init(null, null, null);
486-
SSLSocketFactoryfactory = sslContext.getSocketFactory();
487+
if (upgradeSocketToSSLSocket && "wss".equals(uri.getScheme())){
488+
SSLSocketFactoryfactory;
489+
// Prioritise the provided socketfactory
490+
// Helps when using web debuggers like Fiddler Classic
491+
if (socketFactory != null && (socketFactoryinstanceofSSLSocketFactory)){
492+
factory = (SSLSocketFactory) socketFactory;
493+
} else{
494+
SSLContextsslContext = SSLContext.getInstance("TLSv1.2");
495+
sslContext.init(null, null, null);
496+
factory = sslContext.getSocketFactory();
497+
}
487498
socket = factory.createSocket(socket, uri.getHost(), getPort(), true);
488499
}
489500

0 commit comments

Comments
(0)