diff --git a/HMCLPE/src/main/java/com/tungsten/hmclpe/utils/io/NetworkUtils.java b/HMCLPE/src/main/java/com/tungsten/hmclpe/utils/io/NetworkUtils.java index de830ba6..34981eea 100644 --- a/HMCLPE/src/main/java/com/tungsten/hmclpe/utils/io/NetworkUtils.java +++ b/HMCLPE/src/main/java/com/tungsten/hmclpe/utils/io/NetworkUtils.java @@ -72,8 +72,20 @@ public static List> parseQuery(String queryParameterString) return result; } + private static boolean endsWithDomainSuffix(String host, String domainSuffix) { + return host.endsWith(domainSuffix.toLowerCase()); + } + public static URLConnection createConnection(URL url) throws IOException { URLConnection connection = url.openConnection(); + String host = url.getHost().toLowerCase(); + if (endsWithDomainSuffix(host, "d.pcs.baidu.com") || endsWithDomainSuffix(host, "baidupcs.com")) { + // Docs: https://alist.nn.ci/zh/guide/drivers/baidu.html + connection.setRequestProperty("User-Agent", "pan.baidu.com"); + } else { + // Default + connection.setRequestProperty("User-Agent", "HMCL-PE/2.0.7"); + } connection.setUseCaches(false); connection.setConnectTimeout(5000); connection.setReadTimeout(5000);