1010from .is_heartbeat import is_heartbeat
1111from .is_stream_error import is_stream_error
1212from .is_event import is_event
13+ from .is_valid_server_header import is_valid_server_header
1314from .parse_raw_message import parse_raw_message
1415from .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 } '
0 commit comments