feat: add SOCKS proxy support via aiohttp-socks ProxyConnector#23798
Open
MagicAbdel wants to merge 1 commit into
Open
feat: add SOCKS proxy support via aiohttp-socks ProxyConnector#23798MagicAbdel wants to merge 1 commit into
MagicAbdel wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
2 issues found across 7 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache:82">
P2: Configured SOCKS proxy may be conflicted by environment proxy settings because `self.proxy = None` removes the explicit proxy override while `trust_env=True` remains active on the session.</violation>
</file>
<file name="samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py">
<violation number="1" location="samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py:82">
P1: Connector instantiated in synchronous `__init__` may fail on aiohttp 3.10+ outside a running event loop</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic
| proxy = configuration.proxy | ||
| proxy_scheme = (proxy or "").partition("://")[0].lower() | ||
|
|
||
| if proxy_scheme in SUPPORTED_SOCKS_PROXIES: |
Contributor
There was a problem hiding this comment.
P1: Connector instantiated in synchronous __init__ may fail on aiohttp 3.10+ outside a running event loop
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/python-aiohttp/petstore_api/rest.py, line 82:
<comment>Connector instantiated in synchronous `__init__` may fail on aiohttp 3.10+ outside a running event loop</comment>
<file context>
@@ -74,8 +76,27 @@ def __init__(self, configuration) -> None:
+ proxy = configuration.proxy
+ proxy_scheme = (proxy or "").partition("://")[0].lower()
+
+ if proxy_scheme in SUPPORTED_SOCKS_PROXIES:
+ # SOCKS proxies require ProxyConnector - aiohttp TCPConnector
+ # does not support SOCKS schemes
</file context>
| limit=self.maxsize, | ||
| ssl=self.ssl_context, | ||
| ) | ||
| self.proxy = None # connector handles proxy |
Contributor
There was a problem hiding this comment.
P2: Configured SOCKS proxy may be conflicted by environment proxy settings because self.proxy = None removes the explicit proxy override while trust_env=True remains active on the session.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache, line 82:
<comment>Configured SOCKS proxy may be conflicted by environment proxy settings because `self.proxy = None` removes the explicit proxy override while `trust_env=True` remains active on the session.</comment>
<file context>
@@ -65,8 +67,27 @@ class RESTClientObject:
+ limit=self.maxsize,
+ ssl=self.ssl_context,
+ )
+ self.proxy = None # connector handles proxy
+ self.proxy_headers = None # not applicable for SOCKS
+ else:
</file context>
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.
fixes #23797
This PR adds SOCKS proxy support to the asyncio Python client template.
When a kubeconfig cluster entry contains a
proxy-urlwith a SOCKSscheme (e.g.
socks5://localhost:1080), the async client currentlyfails with:
This happens because
aiohttp.TCPConnectordoes not support SOCKSschemes at the request level — a dedicated
ProxyConnectorfromaiohttp-socksis required at the session level instead.Changes
modules/openapi-generator/src/main/resources/python-asyncio/rest.mustacheSUPPORTED_SOCKS_PROXIESfrozenset constant for the four SOCKSschemes (
socks4,socks4a,socks5,socks5h)partition("://")— no extra dependenciesaiohttp_socks.ProxyConnectorinstead ofaiohttp.TCPConnectorProxyConnectorso non-SOCKS users are unaffectedself.proxy = Nonewhen using SOCKS connector to avoid doubleproxy application per-request
Notes
socks4,socks4a,socks5,socks5haiohttp>=3.10.0andaiohttp-socks>=0.9.0aiohttp-socksis neverimported unless a SOCKS proxy URL is configured
aiohttp-socksinstalled willreceive a clear
ImportErrorinstead of the previous crypticServerDisconnectedErrorself.proxyis set toNonewhen usingProxyConnectorto avoiddouble proxy application — the connector handles routing at the
connection level, not per-request
PR checklist
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Add SOCKS proxy support to the asyncio Python client using
aiohttp-socksProxyConnector, fixing failures whenproxy-urlusessocks*schemes. Fixes #23797.New Features
socks4,socks4a,socks5,socks5hvia session-levelProxyConnector.aiohttpHTTP/HTTPS behavior unchanged.aiohttp>=3.10.0andaiohttp-socks>=0.9.0(install when using SOCKS).Refactors
partition("://")and afrozensetof schemes (no helper function).Written for commit c0cd45c. Summary will update on new commits. Review in cubic