From afd1b08b6daa002f1bf70ebdcf2b3bececc7ba74 Mon Sep 17 00:00:00 2001 From: BingChunMoLi <44092516+BingChunMoLi@users.noreply.github.com> Date: Mon, 18 Aug 2025 23:31:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20maven=20=E6=B5=8B=E9=80=9F=E9=A2=84?= =?UTF-8?q?=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/core.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/framework/core.c b/src/framework/core.c index ec6390f..c2715f7 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -80,7 +80,7 @@ bool chsrc_in_no_color_mode(){return ProgMode.NoColorMode;} static bool in_measure_mode(){return ProgMode.MeasureMode;} static bool in_ipv6_mode(){return ProgMode.Ipv6Mode;} static bool in_dry_run_mode(){return ProgMode.DryRunMode;} - +static bool in_custom_user_agent_mode(){return false;} /** * Target Group mode (相反则称为 standalone mode) @@ -603,20 +603,26 @@ measure_speed_for_url (void *url) ipv6 = "--ipv6"; } + char *user_agent = NULL; + if (in_custom_user_agent_mode()) + { + user_agent = strdup("maven/3.9.11"); + }else{ + user_agent = xy_2strjoin("chsrc/", Chsrc_Version); + } char *os_devnull = xy_os_devnull; /** * @note 我们用 —L,因为部分链接会跳转到其他地方,比如: RubyChina, npmmirror */ - char *curl_cmd = xy_strjoin (8, "curl -qsL ", ipv6, - " -o ", os_devnull, - " -w \"%{http_code} %{speed_download}\" -m", time_sec, - " -A chsrc/" Chsrc_Version " ", url); + char *curl_cmd = xy_strjoin (10, "curl -qsL ", ipv6, + " -o ", os_devnull, + " -w \"%{http_code} %{speed_download}\" -m", time_sec, + " -A ", user_agent, " ", url); // chsrc_info (xy_2strjoin ("测速命令 ", curl_cmd)); - char *curl_buf = xy_run (curl_cmd, 0); - + free(user_agent); return curl_buf; } @@ -1803,4 +1809,4 @@ chsrc_get_cpucore () #endif return cores; -} +} \ No newline at end of file