Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -29,7 +29,6 @@ import java.net.URISyntaxException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilService;
|
||||
import org.jackhuang.hmcl.util.io.HttpRequest;
|
||||
@@ -58,7 +57,7 @@ public class AuthlibInjectorServer implements Observable {
|
||||
|
||||
public static AuthlibInjectorServer locateServer(String url) throws IOException {
|
||||
try {
|
||||
url = addHttpsIfMissing(url);
|
||||
url = NetworkUtils.addHttpsIfMissing(url);
|
||||
HttpURLConnection conn = NetworkUtils.createHttpConnection(url);
|
||||
String ali = conn.getHeaderField("x-authlib-injector-api-location");
|
||||
if (ali != null) {
|
||||
@@ -85,18 +84,6 @@ public class AuthlibInjectorServer implements Observable {
|
||||
}
|
||||
}
|
||||
|
||||
private static String addHttpsIfMissing(String url) throws IOException {
|
||||
if (Pattern.compile("^(?<scheme>[a-zA-Z][a-zA-Z0-9+.-]*)://").matcher(url).find())
|
||||
return url;
|
||||
|
||||
if (url.startsWith("//"))
|
||||
return "https:" + url;
|
||||
else if (url.startsWith("/"))
|
||||
return "https:/" + url;
|
||||
else
|
||||
return "https://" + url;
|
||||
}
|
||||
|
||||
private static boolean urlEqualsIgnoreSlash(String a, String b) {
|
||||
if (!a.endsWith("/"))
|
||||
a += "/";
|
||||
|
||||
@@ -165,7 +165,7 @@ public class Skin {
|
||||
case CUSTOM_SKIN_LOADER_API:
|
||||
String realCslApi = type == Type.LITTLE_SKIN
|
||||
? "https://littleskin.cn/csl"
|
||||
: StringUtils.removeSuffix(Lang.requireNonNullElse(cslApi, ""), "/");
|
||||
: NetworkUtils.addHttpsIfMissing(StringUtils.removeSuffix(Lang.requireNonNullElse(cslApi, ""), "/"));
|
||||
return Task.composeAsync(() -> new GetTask(String.format("%s/%s.json", realCslApi, username)))
|
||||
.thenComposeAsync(json -> {
|
||||
SkinJson result = JsonUtils.GSON.fromJson(json, SkinJson.class);
|
||||
|
||||
@@ -63,6 +63,16 @@ public final class NetworkUtils {
|
||||
return "http".equals(uri.getScheme()) || "https".equals(uri.getScheme());
|
||||
}
|
||||
|
||||
public static String addHttpsIfMissing(String url) {
|
||||
if (Pattern.compile("^(?<scheme>[a-zA-Z][a-zA-Z0-9+.-]*)://").matcher(url).find())
|
||||
return url;
|
||||
|
||||
if (url.startsWith("//"))
|
||||
return "https:" + url;
|
||||
else
|
||||
return "https://" + url;
|
||||
}
|
||||
|
||||
public static String withQuery(String baseUrl, Map<String, String> params) {
|
||||
StringBuilder sb = new StringBuilder(baseUrl);
|
||||
boolean first = true;
|
||||
@@ -126,7 +136,12 @@ public final class NetworkUtils {
|
||||
}
|
||||
|
||||
public static URLConnection createConnection(URI uri) throws IOException {
|
||||
URLConnection connection = uri.toURL().openConnection();
|
||||
URLConnection connection;
|
||||
try {
|
||||
connection = uri.toURL().openConnection();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
connection.setConnectTimeout(TIME_OUT);
|
||||
connection.setReadTimeout(TIME_OUT);
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
|
||||
Reference in New Issue
Block a user