Skip to content

Commit dce8fe0

Browse files
committed
Adding _build_user_agent method
1 parent d403503 commit dce8fe0

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

meilisearch/_httprequests.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import annotations
22

33
import json
4-
from typing import Any, Callable, Dict, List, Optional, Union
4+
from functools import lru_cache
5+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
56

67
import requests
78

@@ -19,7 +20,7 @@ def __init__(self, config: Config) -> None:
1920
self.config = config
2021
self.headers = {
2122
"Authorization": f"Bearer {self.config.api_key}",
22-
"User-Agent": _build_user_agent(config.client_agents),
23+
"User-Agent": self._build_user_agent(config.client_agents),
2324
}
2425

2526
def send_request(
@@ -94,6 +95,14 @@ def delete(
9495
) -> Any:
9596
return self.send_request(requests.delete, path, body)
9697

98+
@lru_cache(maxsize=1)
99+
def _build_user_agent(self, client_agents: Optional[Tuple[str]] = None) -> str:
100+
user_agent = qualified_version()
101+
if not client_agents:
102+
return user_agent
103+
104+
return f"{user_agent};{';'.join(client_agents)}"
105+
97106
@staticmethod
98107
def __to_json(request: requests.Response) -> Any:
99108
if request.content == b"":

meilisearch/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import hmac
99
import json
1010
import re
11-
from typing import Any, Dict, List, Optional, Union
11+
from typing import Any, Dict, List, Optional, Tuple, Union
1212
from urllib import parse
1313

1414
from meilisearch._httprequests import HttpRequests

0 commit comments

Comments
 (0)