Skip to content

Commit

Permalink
Update NetworkUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Tungstend committed Feb 8, 2024
1 parent 0deb083 commit be8fc3a
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,20 @@ public static List<Pair<String, String>> 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);
Expand Down

0 comments on commit be8fc3a

Please sign in to comment.