feat(ws): expose websocket proxy/connect options on Client - #156
Open
Xuxchloris wants to merge 1 commit into
Open
feat(ws): expose websocket proxy/connect options on Client#156Xuxchloris wants to merge 1 commit into
Xuxchloris wants to merge 1 commit into
Conversation
lark.ws.Client forced a direct connection (proxy=None on websockets >= 15) with no supported way to honor HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY or pass explicit websockets.connect() options. Add an optional ws_connect_kwargs parameter to Client.__init__: when provided, the forced direct-connect flag is dropped (so proxies work) and caller values merge over SDK defaults; the default stays exactly as before (issue larksuite#143). 5 new unit tests cover the default path, explicit proxy, env-discovery opt-in, and kwarg merging.
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 #143.
Problem
lark.ws.Clientforces a direct WebSocket connection (onwebsockets >= 15it explicitly passesproxy=None), with no supported way for applications behind an HTTP/HTTPS/SOCKS proxy to make the long-lived event WebSocket honorHTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY— or to pass any customwebsockets.connect()options. The only workaround was monkeypatching the private_ws_connect_kwargs.Change
New optional
ws_connect_kwargsparameter onClient.__init__:None(default): behavior is identical to today — direct connection,proxy=Noneforced on websockets >= 15.proxyworks) and the caller's values merge over SDK defaults.The resolved kwargs are computed once per
_connect()viaClient._resolved_ws_connect_kwargs()and passed towebsockets.connect().Tests
lark_oapi/ws/tests/test_ws_connect_kwargs.py(5 tests):proxywins over the forcedproxy=None;proxykey);Verification
python -m pytest lark_oapi/ws/tests/test_ws_connect_kwargs.py test_redact_conn_url.py— 8/8 pass.