From 977f0b13b3eee5d24919f636041d64df78604980 Mon Sep 17 00:00:00 2001 From: molanp <104612722+molanp@users.noreply.github.com> Date: Mon, 11 Aug 2025 10:18:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(zhenxun):=20=E4=BF=AE=E5=A4=8D=20HTTP=20?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E9=94=99=E8=AF=AF=20(#2014)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 httpx.AsyncClient 实例化逻辑封装到 get_async_client 函数中 - 统一全局客户端和测试环境客户端的创建方式 - 提高代码复用性和可维护性 --- zhenxun/utils/http_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zhenxun/utils/http_utils.py b/zhenxun/utils/http_utils.py index 3b1fceb9..35cae869 100644 --- a/zhenxun/utils/http_utils.py +++ b/zhenxun/utils/http_utils.py @@ -61,7 +61,7 @@ async def _(): "将默认使用新版 'proxy' 参数语法。" ) - _client = httpx.AsyncClient( + _client = get_async_client( headers=get_user_agent(), follow_redirects=True, **client_kwargs, @@ -90,7 +90,7 @@ def get_client() -> AsyncClient: raise RuntimeError("全局 httpx.AsyncClient 未初始化,请检查启动流程。") # 在测试环境中创建临时客户端 logger.warning("在测试环境中创建临时HTTP客户端", "HTTPClient") - _client = httpx.AsyncClient( + _client = get_async_client( headers=get_user_agent(), follow_redirects=True, )