fix(telegram): pass proxy URL explicitly to HTTPXRequest when proxy env vars are set - #8981
Merged
Conversation
…nv vars are set When HTTPS_PROXY / HTTP_PROXY / ALL_PROXY env vars are set (or macOS system proxy is detected), pass the proxy URL explicitly via HTTPXRequest(proxy=proxy_url) instead of relying on httpx's trust_env mechanism, which is unreliable for HTTP CONNECT proxies (e.g. Clash / ClashMac in fake-ip mode). Uses the shared resolve_proxy_url() from base.py (handles env vars + macOS system proxy detection) instead of duplicating env var reading inline. Consolidates the proxy_configured boolean into a single proxy_url = resolve_proxy_url() call that serves as both the gate for skipping fallback-IP transport and the value passed to HTTPXRequest. Co-authored-by: Hermes Agent <hermes@nousresearch.com> Salvaged from PR #8931 by MaybeRichard.
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.
Summary
Salvaged from #8931 by @MaybeRichard.
When
HTTPS_PROXY/HTTP_PROXY/ALL_PROXYenv vars are set, the Telegram adapter correctly detects the proxy and skips the fallback-IP transport — but then createsHTTPXRequestwithout passing the proxy URL explicitly, relying on httpx'strust_envmechanism. This is unreliable for HTTP CONNECT proxies (e.g. Clash/ClashMac in fake-ip mode, common for users in China), causing intermittenthttpx.ConnectError/ConnectTimeoutfailures.Changes
proxy_configuredboolean (which checked env vars and discarded the result) withproxy_url = resolve_proxy_url()fromgateway/platforms/base.py— the shared utility that already handles env vars + macOS system proxy detectionHTTPXRequest(proxy=proxy_url)directlyscutil --proxy) for free viaresolve_proxy_url(), matching howTelegramFallbackTransportalready handles proxyTest plan
resolve_proxy_url()returns correct URL with env vars set, returns None without, priority order correct (HTTPS_PROXY > HTTP_PROXY > ALL_PROXY)Closes #8931