refactor: use urllib.parse for WebSocket URL construction#780
Merged
Conversation
bb38bd9 to
7a6efd5
Compare
ff5cd24 to
f5eb1af
Compare
Replace manual f-string query parameter concatenation and scheme swapping with a shared build_ws_url helper that uses urllib.parse for proper percent-encoding. This fixes free-form values (e.g. keyterms with spaces) producing malformed URLs. Affected files: - realtime/scribe.py — _build_websocket_url - realtime_tts.py — convert_realtime - conversational_ai/conversation.py — _get_wss_url and _get_signed_url Closes #779 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f5eb1af to
3b97a1f
Compare
Pass keep_blank_values=True to parse_qsl so empty-valued parameters (e.g. param=) in the signed URL are not silently dropped. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
urlencode defaults to quote_plus which encodes spaces as `+` instead of `%20`. This can break signed URL signatures when the server validates against the original encoding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PaulAsjes
approved these changes
Apr 29, 2026
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
build_ws_url(base_url, path_segments, params)helper inurl_utils.pythat handles:urllib.parse.urlencodeScribeRealtime._build_websocket_urlinscribe.pyRealtimeTextToSpeechClient.convert_realtimeinrealtime_tts.pyBaseConversation._get_wss_urlinconversation.py_get_signed_urlto useurlparse/urlunparseinstead of string concatenation for appending query paramsCloses #779
Test plan
test_url_utils.pypass (scheme conversion, path encoding, special chars, query params)test_stt_realtime.pypass (including URL construction and scheme conversion)test_convai.py+test_async_convai.pypass (including URL edge cases)🤖 Generated with Claude Code
Note
Medium Risk
Touches WebSocket URL generation for conversation, realtime STT, and realtime TTS; subtle changes in path/query encoding or base-path joining could break connectivity in edge cases.
Overview
Introduces a shared
build_ws_urlhelper to construct WebSocket URLs by converting schemes (http(s)→ws(s)), percent-encoding path segments, and encoding query parameters viaurllib.parse.urlencode.Refactors the conversation, realtime STT (
ScribeRealtime), and realtime TTS URL builders to use this helper instead of manual string/urljoinconstruction, and updates conversation signed-URL augmentation to appendsource/versionviaurlparse/urlunparse.Adds unit tests covering scheme conversion, path joining/encoding, query encoding (including repeated keys), and port/base-path handling.
Reviewed by Cursor Bugbot for commit 3b97a1f. Bugbot is set up for automated code reviews on this repo. Configure here.