Commit 0037b58
fix(config): agent URL 按线路路由(国内 lanlan.app / 国际 www.lanlan.app) (#1491)
* fix(config): agent URL 按线路路由(国内 lanlan.app / 国际 www.lanlan.app)
原本 agent URL 无条件把 lanlan.tech 改写为 lanlan.app,国内外都落到
www.lanlan.app。改为抽出 _normalize_agent_url:统一 tech→app 后,国际
保留 www 前缀,国内剥掉 www 走就近节点;GeoIP 不确定时按国内处理,与
_adjust_free_api_url 口径一致。不含 lanlan 域的自定义 URL 原样返回。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(config): 注释 _normalize_agent_url 的 GeoIP 异常降级语义
回应 code-quality 对空 except 的提醒:补充注释说明探测异常时保留国际
形态作为安全默认,行为不变但可追踪。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(config): 补 bare host 用例固化 agent URL 不补 www 契约
回应 CodeRabbit nitpick:bare lanlan.tech 输入(仅可能来自自定义 URL)
两区都落到 bare lanlan.app,显式记录尊重用户 host、不强加 www 的行为。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(config): agent URL 改写改为按 host 判定,不做字符串级 replace
回应 Codex/CodeRabbit:原裸 replace('www.lanlan.app','lanlan.app') 会
误改 path/query 里出现的同名子串(如自定义代理的 upstream 参数),且比
同文件 _adjust_free_api_url 锚定 /tts 的 www-strip 更松。改为 urlparse
后仅当 host 恰为 lanlan.tech/www.lanlan.tech/lanlan.app/www.lanlan.app
时重写 netloc,其余域一律原样透传,保留端口。
新增用例:query/path 含 lanlan 字样的自定义代理不被改写、evil-lanlan.app
后缀不命中、端口保留。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(config): agent URL 按组件重建 netloc,不动 userinfo
回应 Codex/CodeRabbit:原 netloc.replace(hostname,...) 在 netloc 含
user:pass@ 且凭证里出现 host 同名串时会先替到 userinfo(改坏凭证、host
没动),大小写不一致时也替不到。改为按 username/password/port 组件重建
netloc,host 用规范化后的小写值直接拼,两类场景都稳。
新增用例:user:pass@(凭证含 host 同名串)只改 host。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(config): agent URL 端口非法时原样返回,不拖垮 config 加载
回应 Codex P2:urlparse 不校验端口,.port 访问才对 :abc / 越界端口抛
ValueError。该访问在 GeoIP try 之外,会让 get_core_config() 整体崩溃
(旧字符串 replace 不会)。给 .port 访问加 ValueError guard,非法端口
原样返回交给下游处理。
新增用例:端口非数字 / 越界 → passthrough。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(config): agent URL 保留空但存在的 userinfo 分量
回应 Codex P2:截断式 if parsed.username/password 把空字符串当缺失,
会丢掉 https://:token@host 的整个 :token@(bearer 式代理常用),改坏
认证语义。改用 is not None 区分「分量为空但存在」与「不存在」。
新增用例::token@(空用户名)/ user:@(空密码)均原样保留。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(config): agent URL 保留显式 :0 端口
回应 Codex P2:port 三元用 if parsed.port 截断,端口 0 合法但 falsy,
会把显式 :0 丢成默认端口。与 userinfo 同类,改用 is not None。
新增用例::0 端口保留。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* revert(config): agent URL 改回简单字符串替换,去掉过度工程化的 urlparse
lanlan.tech / lanlan.app 是项目自有域名,AGENT_MODEL_URL 要么是写死的
free 默认,要么是用户自填的非 lanlan 服务 URL。bot review 提的内嵌凭证 /
:0 端口 / :abc 畸形端口 / query 里带 lanlan 字样等场景对这两个域名根本
不会出现,为它们引入 urlparse + netloc 组件重建属于过度工程化。
回到两行 replace(helper 仅为两个调用点复用区域逻辑),测试同步精简。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(config): 给 _normalize_agent_url 的 except 补降级语义注释
revert 时误删了解释注释。空 except 零注释本身不好(与 bot 提不提无关):
补一句说明仅 _check_non_mainland 可能抛、探测失败时保留国际形态。
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Hongzhi Wen <cartabio.coder1@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4b953a7 commit 0037b58
2 files changed
Lines changed: 65 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
628 | 671 | | |
629 | 672 | | |
630 | 673 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2971 | 2971 | | |
2972 | 2972 | | |
2973 | 2973 | | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
| 2991 | + | |
| 2992 | + | |
| 2993 | + | |
2974 | 2994 | | |
2975 | 2995 | | |
2976 | 2996 | | |
| |||
3280 | 3300 | | |
3281 | 3301 | | |
3282 | 3302 | | |
3283 | | - | |
| 3303 | + | |
3284 | 3304 | | |
3285 | 3305 | | |
3286 | 3306 | | |
| |||
3463 | 3483 | | |
3464 | 3484 | | |
3465 | 3485 | | |
3466 | | - | |
| 3486 | + | |
3467 | 3487 | | |
3468 | 3488 | | |
3469 | 3489 | | |
| |||
0 commit comments