Skip to content

Commit

Permalink
Add ResponseCode check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Jun 16, 2023
1 parent a494d1a commit 1c9c18e
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import com.mohistmc.config.MohistConfigUtil;
import com.mohistmc.util.i18n.i18n;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public enum DownloadSource {

MOHIST("https://maven.mohistmc.com/"),
Expand All @@ -38,12 +43,22 @@ public String getUrl() {
return url;
}

public static DownloadSource get(){
public static DownloadSource get() throws IOException {
String ds = MohistConfigUtil.sMohist("libraries_downloadsource", defaultSource.name());
for (DownloadSource me : DownloadSource.values()) {
if (me.name().equalsIgnoreCase(ds))
if (me.name().equalsIgnoreCase(ds)) {
if (isDown(me.url) != 200) return GITHUB;
return me;
}
}
return defaultSource;
}

public static int isDown(String s) throws IOException {
URL url = new URL(s);
URLConnection rulConnection = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
httpUrlConnection.connect();
return httpUrlConnection.getResponseCode();
}
}

0 comments on commit 1c9c18e

Please sign in to comment.