Skip to content

Commit

Permalink
Handling HTTPS connection timeout #70
Browse files Browse the repository at this point in the history
* sets timeout for HTTPS request connection to 10 seconds
* in case of SocketTimeoutException throw warning and fall back to HTTP
  • Loading branch information
frauzufall committed Jan 3, 2019
1 parent 4fc766f commit 8dfce6b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/net/imagej/updater/util/AvailableSites.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@

import javax.net.ssl.SSLHandshakeException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.net.UnknownHostException;
import java.net.*;
import java.util.*;

/**
Expand Down Expand Up @@ -71,6 +68,7 @@ public static void checkHTTPSSupport(LogService log) {
}
try {
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(10000);
} catch (ProtocolException e) {
e.printStackTrace();
}
Expand All @@ -91,6 +89,13 @@ public static void checkHTTPSSupport(LogService log) {
if(log != null) log.warn(msg);
else System.out.println("[WARNING] " + msg);
}
catch(SocketTimeoutException e) {
secureMode = false;
String msg = "Timeout while trying to update securely via HTTPS. Will fall back to HTTP. This is a security risk. " +
"Please contact your system administrator to enable communication via HTTPS.";
if(log != null) log.warn(msg);
else System.out.println("[WARNING] " + msg);
}
catch (IOException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit 8dfce6b

Please sign in to comment.