Repository navigation
Conversation
Signed-off-by: Roxen-AS <akash.arjun12@gmail.com>
Sun-Wukhan
left a comment
There was a problem hiding this comment.
Thanks, this fixes a real dead end for running Live behind a local or plain HTTP proxy: on main _websocket_base_url rewrites every scheme to wss, and connect always passes the ssl kwarg from _websocket_ssl_ctx, which websockets will not accept for a ws:// connection. Mapping http to ws and https to wss, gating the mTLS rewrite on wss, and dropping ssl for non wss URIs all line up with how the URI is actually used.
Three smaller points:
-
The new mapping test covers http to ws and a ws URL passing through unchanged, but not https to wss, which is the production path and the one that must keep the mTLS rewrite. Could you add the https case to
test_websocket_base_url_maps_http_and_preserves_wsso both directions of the table are pinned? -
In
_websocket_base_url, unknown schemes now pass through unchanged, where main forced them towss. A base_url such asftp://hostwould now reach websockets as anftp://URI and fail there with a less clear error, and thesslkwarg would also be dropped by the live.py check. Is passing unknown schemes through deliberate? If not, falling back towssfor anything that is not http or ws would preserve the old behaviour for typos. -
The bytes handling for
url_parts.scheme:urlparseonly returns a bytes scheme when the URL itself is bytes, andHttpOptions.base_urlis typed as a string, so that branch looks unreachable. If a bytes base_url ever did arrive, the rest of the flow would break anyway, for exampleuri.lower().startswith('wss://')in live.py would raise a TypeError on a bytes URI. Suggest dropping the bytes branch to keep the mapping table easy to read, unless there is a caller passing bytes that I missed.
The connect level test asserting that ssl is absent from the captured kwargs for both the http proxy case and the direct ws URL case is exactly the right level to pin this.
Signed-off-by: Roxen-AS <akash.arjun12@gmail.com>
|
Thanks @Sun-Wukhan for the review! Updated
|
Summary
Fixes #3451.
When connecting to the Live API over a plaintext
http://proxy (or an explicitws://URL), two issues prevented WebSocket connections:BaseApiClient._websocket_base_url()unconditionally replaced the URL scheme with'wss'even whenhttp_options.base_urlusedhttp://orws://(and could applyto_mtls_urleven for plaintextws).AsyncLive.connect()unconditionally unpackedself._api_client._websocket_ssl_ctxintows_connect(...), which passesssl=...towebsockets.connectand raisesValueError: ssl argument is incompatible with a ws:// URI.Changes
'http'->'ws'and'https'->'wss'(preserving'ws'/'wss') inBaseApiClient._websocket_base_url(), and only applyto_mtls_urlwhenscheme == 'wss'.'ssl'fromws_connectkwargs inAsyncLive.connect()when the target URI is notwss://(matching_interactions_websocket.py).google/genai/tests/live/test_live.py.Testing
pytest google/genai/tests/live/test_live.py -k "websocket or ssl_kwarg" -q:6 passedpytest google/genai/tests/live/test_live_music.py google/genai/tests/client/test_client_initialization.py -q:166 passedmypy google/genai/_api_client.py google/genai/live.py:Success: no issues found in 2 source files