feat(gateway): unified proxy support with SOCKS, DISCORD_PROXY, and multi-platform coverage#6814
Merged
Conversation
…cOS auto-detection - Add resolve_proxy_url() to base.py — shared by all platform adapters - Check HTTPS_PROXY / HTTP_PROXY / ALL_PROXY env vars first - Fall back to macOS system proxy via scutil --proxy (zero-config) - Pass proxy= to discord.py commands.Bot() for gateway connectivity - Refactor telegram_network.py to use shared resolver - Update test fixtures to accept proxy kwarg
… proxy coverage Follow-up improvements on top of the shared resolver from PR #6562: - Add platform_env_var parameter to resolve_proxy_url() so DISCORD_PROXY takes priority over generic HTTPS_PROXY/ALL_PROXY env vars - Add SOCKS proxy support via aiohttp_socks.ProxyConnector with rdns=True (critical for GFW/Shadowrocket/Clash users — issue #6649) - proxy_kwargs_for_bot() returns connector= for SOCKS, proxy= for HTTP - proxy_kwargs_for_aiohttp() returns split (session_kw, request_kw) for standalone aiohttp sessions - Add proxy support to send_message_tool.py (Discord REST, Slack, SMS) for cron job delivery behind proxies (from PR #2208) - Add proxy support to Discord image/document downloads - Fix duplicate import sys in base.py
This was referenced Apr 9, 2026
Closed
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
Unified proxy support for Discord gateway connections, including SOCKS5 proxy support critical for users behind the GFW. Salvaged from PR #6562 by @nocoo with additional improvements from #2208 by @jhbarnett.
What this PR does:
resolve_proxy_url()inbase.py— unified resolver for all platform adaptersscutil --proxy(zero-config fallback)DISCORD_PROXYenv var override (highest priority, thenHTTPS_PROXY/ALL_PROXY)aiohttp_socks.ProxyConnectorwithrdns=True— required by Shadowrocket, Clash, and most SOCKS implementations for DNS-through-proxysend_message_tool.py(Discord REST, Slack, SMS) for cron deliveryProxy resolution order:
DISCORD_PROXY)HTTPS_PROXY,HTTP_PROXY,ALL_PROXY(+ lowercase)scutil --proxySOCKS handling:
proxy=urlkwarg (native aiohttp)connector=ProxyConnector(url, rdns=True)(requirespip install aiohttp-socks)aiohttp_socks→ graceful fallback with warning logFiles Changed
gateway/platforms/base.py— shared resolver + SOCKS connector helpersgateway/platforms/discord.py— proxy for Bot, image download, document downloadgateway/platforms/telegram_network.py— delegate to shared resolvertools/send_message_tool.py— proxy for Discord REST, Slack, SMStests/gateway/test_discord_connect.py— updated mocks for proxy kwargTest Results
Credits
Cherry-picked from PR #6562 by @nocoo (shared resolver, macOS detect, DRY Telegram). Additional proxy coverage for send_message_tool inspired by PR #2208 by @jhbarnett. SOCKS support addresses #6649 by @Microstronggo.
Fixes #6649
Supersedes #6562, #6052, #6184, #2208