feat: 正向代理支持(企业私有化外网出口),内网地址自动直连 - #186
Open
tianling536 wants to merge 1 commit into
Open
Conversation
- 新增 app/net_proxy.py 统一收口:显式配置(.env HTTP_PROXY/HTTPS_PROXY/ NO_PROXY)> 进程环境变量;私网 IP/localhost/无点主机名恒直连, no_proxy 支持域名后缀(.corp.example)、精确主机与 * - 启动期 apply_proxy_env 把显式配置收敛进 os.environ(大小写双写), httpx(trust_env)/websockets(getproxies)/pip 全栈生效——企微 WS SDK 无代理参数也由此覆盖;飞书 lark SDK 走原生 proxy_url/trust_env_proxy - httpx 主路径(模型 OpenAI/Anthropic/Gemini、工具、MCP、微信/钉钉/ 飞书 API)按目标 URL 显式注入 proxy 或无代理 mounts(强制直连), 内网模型服务绝不被代理出去 - 沙箱 env 白名单放行代理变量,allowlist 网络策略自动并入代理主机 - .env.example 增代理与 PyPI 镜像条目;README 中英加部署说明 - 测试 9 例:私网自动绕过/后缀通配/显式优先/绕过 mounts/环境收敛/ 未配置不覆盖既有环境/allowlist 代理主机
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
企业私有化部署下外网访问必须走正向代理。本 PR 新增统一代理支持:
.env配置三项(HTTP_PROXY/HTTPS_PROXY/NO_PROXY)后,模型调用、工具/MCP、微信/企微/飞书/钉钉渠道、沙箱内技能代码、pip 依赖安装全栈生效,且内网模型服务绝不被代理出去。设计(
backend/app/net_proxy.py统一收口)no_proxy命中 / 私网自动绕过 > 显式配置 > 进程环境变量;10./172.16./192.168./127.私网地址、localhost、无点主机名恒直连无需配置;no_proxy支持域名后缀(.corp.internal覆盖全部子域)、精确主机、*全直连;apply_proxy_env()(startup 首个动作)把显式配置写入os.environ(大小写双写)——httpx(trust_env)、websockets(getproxies/proxy_bypass)、pip 全部自动生效,不支持显式代理参数的企微 WS SDK(aibot)也由此覆盖;proxy=;proxy_url/trust_env_proxy(显式配置走前者,否则后者读环境);allowlist网络策略下代理主机自动并入允许域;deny模式不受影响。配置示例
内网 IP 与 localhost 不用写进名单(自动直连)。
.env.example已加模板(另补上此前缺失的 PyPI 内网镜像三项),README 中英各有一节部署说明。验证
tests/test_net_proxy.py9 例:私网自动绕过、后缀/通配匹配、显式优先、绕过 mounts 形态、环境收敛、未配置不覆盖既有环境、allowlist 代理主机;test_llm_client.py等,纯净 main 同测同挂,与本 PR 无关);ruff 通过(tests/test_markdown_render.py的 3 处 E741 同为 main 预存在)。说明