Skip to content

Commit

Permalink
Merge pull request #377 from dvonthenen/fix-ws-http-client-options
Browse files Browse the repository at this point in the history
Fix `ws(s)://` for Streaming for On-Prem
  • Loading branch information
dvonthenen committed Apr 24, 2024
2 parents b52c70d + c7dc922 commit 88945ca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions deepgram/clients/live/helpers.py
Expand Up @@ -4,6 +4,7 @@

from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
from typing import Dict
import re


# This function appends query parameters to a URL
Expand All @@ -29,11 +30,11 @@ def append_query_params(url: str, params: Dict):

# This function converts a URL to a WebSocket URL
def convert_to_websocket_url(base_url: str, endpoint: str):
if re.match(r"^https?://", base_url, re.IGNORECASE):
base_url = base_url.replace("https://", "").replace("http://", "")
if not re.match(r"^wss?://", base_url, re.IGNORECASE):
base_url = "wss://" + base_url
parsed_url = urlparse(base_url)
domain = parsed_url.netloc
if parsed_url.scheme == "https":
websocket_scheme = "wss"
else:
websocket_scheme = "ws"
websocket_url = urlunparse((websocket_scheme, domain, endpoint, "", "", ""))
websocket_url = urlunparse((parsed_url.scheme, domain, endpoint, "", "", ""))
return websocket_url

0 comments on commit 88945ca

Please sign in to comment.