Skip to content

Commit 98f53ba

Browse files
authored
Merge pull request #9 from wherobots/peter/protocol
feat: adds protocol version to the connection path
2 parents 5e10986 + 167364a commit 98f53ba

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

wherobots/db/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
DEFAULT_READ_TIMEOUT_SECONDS: float = 0.25
1313
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS: float = 300
1414
MAX_MESSAGE_SIZE: int = 100 * 2**20 # 100MiB
15+
PROTOCOL_VERSION: str = "1.0.0"
1516

1617

1718
class ExecutionState(LowercaseStrEnum):

wherobots/db/driver.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import logging
7+
import os
78
import urllib.parse
89
import queue
910
import requests
@@ -18,6 +19,7 @@
1819
DEFAULT_READ_TIMEOUT_SECONDS,
1920
DEFAULT_SESSION_WAIT_TIMEOUT_SECONDS,
2021
MAX_MESSAGE_SIZE,
22+
PROTOCOL_VERSION,
2123
ResultsFormat,
2224
DataCompression,
2325
GeometryRepresentation,
@@ -134,6 +136,11 @@ def http_to_ws(uri: str) -> str:
134136
return str(urllib.parse.urlunparse(parsed))
135137

136138

139+
def append_protocol(uri: str, protocol: str) -> str:
140+
"""Appends the protocol version to the URI."""
141+
return urllib.parse.urljoin(os.path.join(uri, ""), protocol)
142+
143+
137144
def connect_direct(
138145
uri: str,
139146
headers: dict[str, str] = None,
@@ -143,12 +150,13 @@ def connect_direct(
143150
geometry_representation: GeometryRepresentation | None = None,
144151
) -> Connection:
145152
q = queue.SimpleQueue()
153+
uri_with_protocol = append_protocol(uri, PROTOCOL_VERSION)
146154

147155
def create_ws_connection():
148156
try:
149-
logging.info("Connecting to SQL session at %s ...", uri)
157+
logging.info("Connecting to SQL session at %s ...", uri_with_protocol)
150158
ws = websockets.sync.client.connect(
151-
uri=uri,
159+
uri=uri_with_protocol,
152160
additional_headers=headers,
153161
max_size=MAX_MESSAGE_SIZE,
154162
)

0 commit comments

Comments
 (0)