不对回环地址应用代理 (#4338)

This commit is contained in:
Glavo
2025-08-27 21:43:54 +08:00
committed by GitHub
parent 1ddb73595d
commit 73214ad599
3 changed files with 75 additions and 24 deletions

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.util.io;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.io.*;
@@ -45,6 +46,19 @@ public final class NetworkUtils {
private NetworkUtils() {
}
public static boolean isLoopbackAddress(URI uri) {
String host = uri.getHost();
if (StringUtils.isBlank(host))
return false;
try {
InetAddress addr = InetAddress.getByName(host);
return addr.isLoopbackAddress();
} catch (UnknownHostException e) {
return false;
}
}
public static boolean isHttpUri(URI uri) {
return "http".equals(uri.getScheme()) || "https".equals(uri.getScheme());
}