Skip to content

Commit

Permalink
use a non-SSL websocket connection if http:// was specifies
Browse files Browse the repository at this point in the history
The code currently only supports SSL-secured websocket connections, which means the SDK doesn't support testing self-hosted deployments when running on the self-hosted server itself (i.e. `ws://` connections).

This change updates the code to use `ws://` rather than `wss://` when the user specifies `http://` in their `api_url`.
  • Loading branch information
jjmaldonis authored Aug 8, 2024
1 parent 78ec6d9 commit 40b9d44
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion deepgram/clients/listen/v1/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ def convert_to_websocket_url(base_url: str, endpoint: str):
"""
Converts a URL to a WebSocket URL
"""
use_ssl = True # Default to true
if re.match(r"^https?://", base_url, re.IGNORECASE):
if "http://" in base_url:
use_ssl = False # Override to false if http:// is found
base_url = base_url.replace("https://", "").replace("http://", "")
if not re.match(r"^wss?://", base_url, re.IGNORECASE):
base_url = "wss://" + base_url
if use_ssl:
base_url = "wss://" + base_url
else:
base_url = "ws://" + base_url
parsed_url = urlparse(base_url)
domain = parsed_url.netloc
websocket_url = urlunparse((parsed_url.scheme, domain, endpoint, "", "", ""))
Expand Down

0 comments on commit 40b9d44

Please sign in to comment.