Skip to content

Commit 8c6d809

Browse files
authored
user agent in transport (#37)
1 parent 542f3e3 commit 8c6d809

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

src/fr24sdk/transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import httpx
1111

12+
from . import __version__
1213
from .exceptions import (
1314
ApiError,
1415
AuthenticationError,
@@ -25,6 +26,7 @@
2526
DEFAULT_BASE_URL = "https://fr24api.flightradar24.com"
2627
DEFAULT_API_VERSION = "v1"
2728
DEFAULT_TIMEOUT_SECONDS = 30
29+
DEFAULT_USER_AGENT = f"FR24 API Python SDK/{__version__}"
2830

2931

3032
class HttpTransport:
@@ -57,6 +59,7 @@ def _get_default_headers(self) -> dict[str, str]:
5759
headers = {
5860
"Accept": "application/json",
5961
"Accept-Version": self.api_version,
62+
"User-Agent": DEFAULT_USER_AGENT,
6063
}
6164
if self.api_token:
6265
headers["Authorization"] = f"Bearer {self.api_token}"

tests/unit/test_transport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
DEFAULT_BASE_URL,
1515
DEFAULT_API_VERSION,
1616
DEFAULT_TIMEOUT_SECONDS,
17+
DEFAULT_USER_AGENT,
1718
)
1819
from fr24sdk.exceptions import (
1920
ApiError,
@@ -122,6 +123,7 @@ def test_default_headers(transport: HttpTransport) -> None:
122123
headers = transport._get_default_headers()
123124
assert headers["Accept"] == "application/json"
124125
assert headers["Accept-Version"] == DEFAULT_API_VERSION
126+
assert headers["User-Agent"] == DEFAULT_USER_AGENT
125127
assert headers["Authorization"] == f"Bearer {TEST_TOKEN}"
126128

127129

@@ -170,6 +172,7 @@ def test_request_with_params_and_custom_headers() -> None: # Removed respx_rout
170172
sent_headers = route.calls.last.request.headers
171173
assert sent_headers["x-custom-header"] == "custom_value"
172174
assert sent_headers["accept"] == "application/json"
175+
assert sent_headers["user-agent"] == DEFAULT_USER_AGENT
173176
assert sent_headers["authorization"] == f"Bearer {TEST_TOKEN}"
174177

175178

0 commit comments

Comments
 (0)