mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-13 17:46:58 +08:00
fix: IllegalArgumentException
This commit is contained in:
parent
383de6cb2e
commit
eb9d123176
@ -60,32 +60,36 @@ public class AuthlibInjectorServer implements Observable {
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
|
||||
public static AuthlibInjectorServer locateServer(String url) throws IOException {
|
||||
url = parseInputUrl(url);
|
||||
HttpURLConnection conn;
|
||||
int redirectCount = 0;
|
||||
for (;;) {
|
||||
conn = (HttpURLConnection) new URL(url).openConnection();
|
||||
Optional<String> ali = getApiLocationIndication(conn);
|
||||
if (ali.isPresent()) {
|
||||
conn.disconnect();
|
||||
url = ali.get();
|
||||
if (redirectCount >= MAX_REDIRECTS) {
|
||||
throw new IOException("Exceeded maximum number of redirects (" + MAX_REDIRECTS + ")");
|
||||
}
|
||||
redirectCount++;
|
||||
LOG.info("Redirect API root to: " + url);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AuthlibInjectorServer server = new AuthlibInjectorServer(url);
|
||||
server.refreshMetadata(readFullyWithoutClosing(conn.getInputStream()));
|
||||
return server;
|
||||
} finally {
|
||||
conn.disconnect();
|
||||
url = parseInputUrl(url);
|
||||
HttpURLConnection conn;
|
||||
int redirectCount = 0;
|
||||
for (; ; ) {
|
||||
conn = (HttpURLConnection) new URL(url).openConnection();
|
||||
Optional<String> ali = getApiLocationIndication(conn);
|
||||
if (ali.isPresent()) {
|
||||
conn.disconnect();
|
||||
url = ali.get();
|
||||
if (redirectCount >= MAX_REDIRECTS) {
|
||||
throw new IOException("Exceeded maximum number of redirects (" + MAX_REDIRECTS + ")");
|
||||
}
|
||||
redirectCount++;
|
||||
LOG.info("Redirect API root to: " + url);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AuthlibInjectorServer server = new AuthlibInjectorServer(url);
|
||||
server.refreshMetadata(readFullyWithoutClosing(conn.getInputStream()));
|
||||
return server;
|
||||
} finally {
|
||||
conn.disconnect();
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user