Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use an unsecured websocket connection if http:// was specified #450

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading