Skip to content

Commit 88945ca

Browse files
Merge pull request #377 from dvonthenen/fix-ws-http-client-options
Fix `ws(s)://` for Streaming for On-Prem
2 parents b52c70d + c7dc922 commit 88945ca

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

deepgram/clients/live/helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
66
from typing import Dict
7+
import re
78

89

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

3031
# This function converts a URL to a WebSocket URL
3132
def convert_to_websocket_url(base_url: str, endpoint: str):
33+
if re.match(r"^https?://", base_url, re.IGNORECASE):
34+
base_url = base_url.replace("https://", "").replace("http://", "")
35+
if not re.match(r"^wss?://", base_url, re.IGNORECASE):
36+
base_url = "wss://" + base_url
3237
parsed_url = urlparse(base_url)
3338
domain = parsed_url.netloc
34-
if parsed_url.scheme == "https":
35-
websocket_scheme = "wss"
36-
else:
37-
websocket_scheme = "ws"
38-
websocket_url = urlunparse((websocket_scheme, domain, endpoint, "", "", ""))
39+
websocket_url = urlunparse((parsed_url.scheme, domain, endpoint, "", "", ""))
3940
return websocket_url

0 commit comments

Comments
 (0)