Skip to content

fix: no_proxy 兜底不再覆盖用户原有的 bypass 列表,补 5 个单测 - #38

Merged
longsizhuo merged 1 commit into
masterfrom
fix/pr34-followup
Aug 4, 2026
Merged

longsizhuo merged 1 commit into
masterfrom
fix/pr34-followup

Conversation

@longsizhuo

@longsizhuo longsizhuo commented Aug 4, 2026 •

Copy link
Copy Markdown
Owner

#34 的 follow-up。修法本身是对的(核过:HTTPApi._request 走 urllib.request.urlopen,ProxyHandler.proxy_open 每次请求都现调 proxy_bypass 重读 env,所以起浏览器前设一次就生效),但实现有个真 bug,另外没单测。

Bug:no_proxy 被显式设成空串时会丢掉用户原有的 bypass 列表。

no_proxy = os.environ.get("no_proxy", os.environ.get("NO_PROXY", ""))

key 存在但值为空串时 get 返回 "",default 分支根本不执行 —— 读不到 NO_PROXY,接着下面把它整个覆盖成 127.0.0.1,localhost。POSIX 上这俩是独立变量所以能真触发(Windows 的 os.environ 大小写不敏感,碰不到)。httpx 也读这两个变量,所以用户的公司内网 bypass 规则会在跑脚本期间静默失效。

顺带两条:追加而不是 sorted(set) 重排,保留原有顺序;按小写去重,避免已有 LOCALHOST 时每次启动列表都变长一截。

补 5 个单测,原 PR 一个都没有。其中 falls_back_to_uppercase 是上面那个 bug 的回归测试,只在 POSIX 上真正生效,CI 跑 ubuntu 所以能覆盖。

208 passed, 1 skipped。

Copilot AI lite review requested due to automatic review settings August 4, 2026 19:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

#34 的 follow-up。os.environ.get("no_proxy", os.environ.get("NO_PROXY", ""))
在 key 存在但值为空串时返回 "",default 分支不执行 —— 读不到 NO_PROXY,接着
把它整个覆盖成 "127.0.0.1,localhost"。POSIX 上这俩是独立变量所以能真触发;
httpx 也读它们,用户的内网 bypass 规则会连带失效。

顺带:追加而不是 sorted(set) 重排,保留原有顺序;按小写去重,避免已有
LOCALHOST 时每次启动列表都变长。补 5 个单测(原 PR 没有)。
@longsizhuo
longsizhuo merged commit df15be7 into master Aug 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants