Skip to content

feat(ws): expose websocket proxy/connect options on Client - #156

Open
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/ws-connect-kwargs
Open

feat(ws): expose websocket proxy/connect options on Client#156
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/ws-connect-kwargs

Conversation

@Xuxchloris

Copy link
Copy Markdown

Fixes #143.

Problem

lark.ws.Client forces a direct WebSocket connection (on websockets >= 15 it explicitly passes proxy=None), with no supported way for applications behind an HTTP/HTTPS/SOCKS proxy to make the long-lived event WebSocket honor HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY — or to pass any custom websockets.connect() options. The only workaround was monkeypatching the private _ws_connect_kwargs.

Change

New optional ws_connect_kwargs parameter on Client.__init__:

  • None (default): behavior is identical to today — direct connection, proxy=None forced on websockets >= 15.
  • Provided: the forced direct-connect flag is dropped (so environment proxy discovery or an explicit proxy works) and the caller's values merge over SDK defaults.

The resolved kwargs are computed once per _connect() via Client._resolved_ws_connect_kwargs() and passed to websockets.connect().

Tests

lark_oapi/ws/tests/test_ws_connect_kwargs.py (5 tests):

  • default preserves the historical direct-connect kwargs;
  • explicit proxy wins over the forced proxy=None;
  • empty dict opts into environment proxy discovery (no proxy key);
  • caller values merge with SDK defaults;
  • the websockets-signature detection still behaves as before.

Verification

  • python -m pytest lark_oapi/ws/tests/test_ws_connect_kwargs.py test_redact_conn_url.py — 8/8 pass.

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.
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.

[Feature Request] Expose public WebSocket proxy/connect options on ws.Client

1 participant