add: useragent - if domain suffix

This commit is contained in:
8Mi_Yile 2024-01-11 11:30:03 +08:00 committed by GitHub
parent 6d5aaad7f1
commit 743483fdfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -84,8 +84,20 @@ public final class NetworkUtils {
return result; return result;
} }
private static boolean endsWithDomainSuffix(String host, String domainSuffix) {
return host.endsWith(domainSuffix.toLowerCase());
}
public static URLConnection createConnection(URL url) throws IOException { public static URLConnection createConnection(URL url) throws IOException {
URLConnection connection = url.openConnection(); 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", "FCL/1.1.3");
}
connection.setUseCaches(false); connection.setUseCaches(false);
connection.setConnectTimeout(5000); connection.setConnectTimeout(5000);
connection.setReadTimeout(5000); connection.setReadTimeout(5000);