From 7998ede44a6db6abf9bcbd22cd0143849307c8d4 Mon Sep 17 00:00:00 2001 From: libm Date: Wed, 31 Dec 2025 15:15:18 +0800 Subject: [PATCH] feat(clashsub): support custom User-Agent for subscription download Fix #414 --- .env | 3 +++ scripts/cmd/common.sh | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 9990c0c..6c69a41 100644 --- a/.env +++ b/.env @@ -7,6 +7,9 @@ CLASH_BASE_DIR=~/clashctl # 机场订阅 CLASH_CONFIG_URL= +# 下载订阅时的 UserAgent +CLASH_SUB_UA=clash + # init 系统(自动识别) INIT_TYPE= diff --git a/scripts/cmd/common.sh b/scripts/cmd/common.sh index 75f693f..c72a92d 100755 --- a/scripts/cmd/common.sh +++ b/scripts/cmd/common.sh @@ -146,7 +146,6 @@ function _download_config() { _download_raw_config() { local dest=$1 local url=$2 - local agent='clash' curl \ --silent \ @@ -156,7 +155,7 @@ _download_raw_config() { --location \ --max-time 5 \ --retry 1 \ - --user-agent "$agent" \ + --user-agent "$CLASH_SUB_UA" \ --output "$dest" \ "$url" || wget \ @@ -164,7 +163,7 @@ _download_raw_config() { --no-check-certificate \ --timeout 5 \ --tries 1 \ - --user-agent "$agent" \ + --user-agent "$CLASH_SUB_UA" \ --output-document "$dest" \ "$url" } @@ -188,7 +187,7 @@ _download_convert_config() { --write-out '%{url_effective}' \ "$base_url" ) - curl --silent --output "$dest" "$convert_url" + curl --user-agent "$CLASH_SUB_UA" --silent --output "$dest" "$convert_url" flag=$? _stop_convert return $flag