11from __future__ import annotations
22
3+ from functools import lru_cache
34from typing import Any , Callable
45
56from httpx import (
1112 Response ,
1213)
1314
15+ from meilisearch_python_async ._version import get_version
1416from meilisearch_python_async .errors import (
1517 MeilisearchApiError ,
1618 MeilisearchCommunicationError ,
@@ -27,19 +29,18 @@ async def _send_request(
2729 http_method : Callable ,
2830 path : str ,
2931 body : Any | None = None ,
30- content_type : str = "applicaiton /json" ,
32+ content_type : str = "applicaton /json" ,
3133 ) -> Response :
34+ headers = {"user-agent" : user_agent ()}
3235 try :
3336 if not body :
3437 response = await http_method (path )
3538 elif content_type != "application/json" :
36- response = await http_method (
37- path , content = body , headers = {"Content-Type" : content_type }
38- )
39+ headers ["Content-Type" ] = content_type
40+ response = await http_method (path , content = body , headers = headers )
3941 else :
40- response = await http_method (
41- path , json = body , headers = {"Content-Type" : content_type }
42- )
42+ headers ["Content-Type" ] = content_type
43+ response = await http_method (path , json = body , headers = headers )
4344
4445 response .raise_for_status ()
4546 return response
@@ -73,3 +74,8 @@ async def put(
7374
7475 async def delete (self , path : str , body : dict | None = None ) -> Response :
7576 return await self ._send_request (self .http_client .delete , path , body )
77+
78+
79+ @lru_cache (maxsize = 1 )
80+ def user_agent () -> str :
81+ return f"Meilisearch Python Async (v{ get_version ()} )"
0 commit comments