fix(zhenxun): 修复 HTTP 客户端初始化逻辑错误

- 将 httpx.AsyncClient 实例化逻辑封装到 get_async_client 函数中
- 统一全局客户端和测试环境客户端的创建方式
- 提高代码复用性和可维护性
This commit is contained in:
molanp 2025-08-08 01:33:25 +08:00
parent 3deffcb46c
commit c7793d1de7

View File

@ -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,
)