Skip to content

Commit 1c00b21

Browse files
authored
Merge branch 'main' into dependabot/pip/cryptography-44.0.1
2 parents 04d944d + a17d8f3 commit 1c00b21

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

eventsourcingdb/client.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .is_heartbeat import is_heartbeat
1111
from .is_stream_error import is_stream_error
1212
from .is_event import is_event
13+
from .is_valid_server_header import is_valid_server_header
1314
from .parse_raw_message import parse_raw_message
1415
from .read_events import ReadEventsOptions
1516

@@ -56,6 +57,8 @@ async def ping(self) -> None:
5657
ping_received_type = "io.eventsourcingdb.api.ping-received"
5758

5859
response = await self.http_client.get("/api/v1/ping")
60+
if not is_valid_server_header(response):
61+
raise ServerError("Server must be EventSourcingDB")
5962
response_body = bytes.decode(await response.body.read(), encoding="utf-8")
6063

6164
if response.status_code != HTTPStatus.OK:
@@ -80,6 +83,8 @@ async def verify_api_token(self) -> None:
8083
request_body=request_body,
8184
)
8285
async with response:
86+
if not is_valid_server_header(response):
87+
raise ServerError("Server must be EventSourcingDB")
8388
if response.status_code != HTTPStatus.OK:
8489
raise ServerError(
8590
f'Failed to verify API token: {response}'
@@ -118,6 +123,8 @@ async def write_events(
118123
request_body=request_body,
119124
)
120125

126+
if not is_valid_server_header(response):
127+
raise ServerError("Server must be EventSourcingDB")
121128
if response.status_code != HTTPStatus.OK:
122129
raise ServerError(
123130
f'Unexpected response status: {response}'
@@ -151,6 +158,8 @@ async def read_events(
151158
)
152159

153160
async with response:
161+
if not is_valid_server_header(response):
162+
raise ServerError("Server must be EventSourcingDB")
154163
if response.status_code != HTTPStatus.OK:
155164
raise ServerError(
156165
f'Unexpected response status: {response}'
@@ -181,6 +190,8 @@ async def run_eventql_query(self, query: str) -> AsyncGenerator[Any]:
181190
)
182191

183192
async with response:
193+
if not is_valid_server_header(response):
194+
raise ServerError("Server must be EventSourcingDB")
184195
if response.status_code != HTTPStatus.OK:
185196
raise ServerError(
186197
f'Unexpected response status: {response}'
@@ -222,6 +233,8 @@ async def observe_events(
222233
)
223234

224235
async with response:
236+
if not is_valid_server_header(response):
237+
raise ServerError("Server must be EventSourcingDB")
225238
if response.status_code != HTTPStatus.OK:
226239
raise ServerError(
227240
f'Unexpected response status: {response}'
@@ -257,6 +270,8 @@ async def register_event_schema(self, event_type: str, json_schema: dict) -> Non
257270
)
258271

259272
async with response:
273+
if not is_valid_server_header(response):
274+
raise ServerError("Server must be EventSourcingDB")
260275
if response.status_code != HTTPStatus.OK:
261276
raise ServerError(
262277
f'Unexpected response status: {response} '
@@ -276,6 +291,8 @@ async def read_subjects(
276291
)
277292

278293
async with response:
294+
if not is_valid_server_header(response):
295+
raise ServerError("Server must be EventSourcingDB")
279296
if response.status_code != HTTPStatus.OK:
280297
raise ServerError(
281298
f'Unexpected response status: {response}'
@@ -306,6 +323,8 @@ async def read_event_type(self, event_type: str) -> EventType:
306323
)
307324

308325
async with response:
326+
if not is_valid_server_header(response):
327+
raise ServerError("Server must be EventSourcingDB")
309328
if response.status_code != HTTPStatus.OK:
310329
raise ServerError(
311330
f'Unexpected response status: {response}'
@@ -340,6 +359,8 @@ async def read_event_types(self) -> AsyncGenerator[EventType]:
340359
raise InternalError(str(other_error)) from other_error
341360

342361
async with response:
362+
if not is_valid_server_header(response):
363+
raise ServerError("Server must be EventSourcingDB")
343364
if response.status_code != HTTPStatus.OK:
344365
raise ServerError(
345366
f'Unexpected response status: {response}'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from .http_client import Response
2+
3+
4+
def is_valid_server_header(response: Response) -> bool:
5+
server_header = response.headers.get('Server')
6+
7+
if not server_header:
8+
return False
9+
10+
if not server_header.startswith('EventSourcingDB/'):
11+
return False
12+
13+
return True

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "eventsourcingdb"
3-
version = "1.6.0"
3+
version = "1.7.0"
44
description = "The official Python client SDK for EventSourcingDB."
55
authors = [{ name = "the native web GmbH", email = "[email protected]" }]
66
requires-python = ">=3.11, <=3.13"

0 commit comments

Comments
 (0)