From d9991eedbc9152e0110dd57d7fbdb45be554a34b Mon Sep 17 00:00:00 2001 From: yawiii <77927734@qq.com> Date: Wed, 8 Apr 2026 10:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=BA=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E7=9B=B4=E8=BF=9E=E8=80=8C=E5=AF=BC=E8=87=B4=E6=8A=9B?= =?UTF-8?q?=E5=87=BA=E7=BD=91=E7=BB=9C=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 13 +++++++++++++ services/core.py | 14 +++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d50e83a --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.agents/ +.claude/ +.codebuddy/ +.kiro/ +.trae/ +__pycache__/ +*.pyc +*.pyo +*.pyd +.DS_Store +skills-lock.json +js/version.js +doc/ \ No newline at end of file diff --git a/services/core.py b/services/core.py index 7269366..44d9467 100644 --- a/services/core.py +++ b/services/core.py @@ -75,19 +75,23 @@ class HTTPClientPool: if not client.is_closed: return client + # 智能判定是否为本地地址 + is_local = False + if base_url: + is_local = any(host in str(base_url) for host in ['localhost', '127.0.0.1', '0.0.0.0', '[::1]']) + # 创建新客户端 client_kwargs = { 'timeout': httpx.Timeout(timeout, connect=10.0, read=timeout, write=60.0), 'verify': verify_ssl, 'follow_redirects': True, 'http2': False, - # 关键修复:禁用系统环境变量代理配置 - # 避免 HTTP_PROXY/HTTPS_PROXY 导致 localhost 请求被代理拦截返回 502 - 'trust_env': False, + # 关键修复:根据目标地址智能控制系统代理配置 + # 避免 HTTP_PROXY/HTTPS_PROXY 拦截本地请求,同时允许外部请求(如xflow, openai)使用代理 + 'trust_env': not is_local, # 设置连接池保持连接 'limits': httpx.Limits(max_keepalive_connections=10, max_connections=20, keepalive_expiry=60.0) - } - + } if proxy: client_kwargs['proxies'] = proxy