mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
client: adds X-Client-Id header to pydase.Client
This commit is contained in:
parent
9424d4c412
commit
c5e1a08c54
@ -84,6 +84,7 @@ class Client:
|
||||
url: str,
|
||||
block_until_connected: bool = True,
|
||||
sio_client_kwargs: dict[str, Any] = {},
|
||||
client_id: str = "pydase_client",
|
||||
):
|
||||
# Parse the URL to separate base URL and path prefix
|
||||
parsed_url = urllib.parse.urlparse(url)
|
||||
@ -98,6 +99,7 @@ class Client:
|
||||
self._url = url
|
||||
self._sio = socketio.AsyncClient(**sio_client_kwargs)
|
||||
self._loop = asyncio.new_event_loop()
|
||||
self._client_id = client_id
|
||||
self.proxy = ProxyClass(
|
||||
sio_client=self._sio, loop=self._loop, reconnect=self.connect
|
||||
)
|
||||
@ -137,7 +139,10 @@ class Client:
|
||||
logger.debug("Connecting to server '%s' ...", self._url)
|
||||
await self._setup_events()
|
||||
await self._sio.connect(
|
||||
self._base_url,
|
||||
url=self._base_url,
|
||||
headers={
|
||||
"X-Client-Id": self._client_id,
|
||||
},
|
||||
socketio_path=f"{self._path_prefix}/ws/socket.io",
|
||||
transports=["websocket"],
|
||||
retry=True,
|
||||
|
@ -161,3 +161,15 @@ def test_context_manager(pydase_client: pydase.Client) -> None:
|
||||
assert client.proxy.my_property == 1337.01
|
||||
|
||||
assert not client.proxy.connected
|
||||
|
||||
|
||||
def test_client_id(
|
||||
pydase_client: pydase.Client, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
pydase.Client(url="ws://localhost:9999")
|
||||
|
||||
assert "Client [id=pydase_client] connected" in caplog.text
|
||||
caplog.clear()
|
||||
|
||||
pydase.Client(url="ws://localhost:9999", client_id="my_service")
|
||||
assert "Client [id=my_service] connected" in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user