Skip to content

Commit

Permalink
Merge pull request #450 from deepgram/jason/allow-non-ssl-websocket-c…
Browse files Browse the repository at this point in the history
…onnections

use an unsecured websocket connection if http:// was specified
  • Loading branch information
davidvonthenen authored Aug 8, 2024
2 parents 78ec6d9 + 40b9d44 commit 91fc36d
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 91fc36d

Please sign in to comment.