From 743483fdfb8bb70db67867888090ea89ac43bcf0 Mon Sep 17 00:00:00 2001 From: 8Mi_Yile Date: Thu, 11 Jan 2024 11:30:03 +0800 Subject: [PATCH] add: useragent - if domain suffix --- .../com/tungsten/fclcore/util/io/NetworkUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/FCLCore/src/main/java/com/tungsten/fclcore/util/io/NetworkUtils.java b/FCLCore/src/main/java/com/tungsten/fclcore/util/io/NetworkUtils.java index ca45854b..cf4b4802 100644 --- a/FCLCore/src/main/java/com/tungsten/fclcore/util/io/NetworkUtils.java +++ b/FCLCore/src/main/java/com/tungsten/fclcore/util/io/NetworkUtils.java @@ -84,8 +84,20 @@ public final class NetworkUtils { 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", "FCL/1.1.3"); + } connection.setUseCaches(false); connection.setConnectTimeout(5000); connection.setReadTimeout(5000);