From 5863c45f6abfa0a87cd7b50db96e64d4d89a254a Mon Sep 17 00:00:00 2001 From: Damian Szumski Date: Tue, 24 Mar 2026 11:43:39 +0100 Subject: [PATCH] user agent in transport --- src/fr24sdk/transport.py | 3 +++ tests/unit/test_transport.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/fr24sdk/transport.py b/src/fr24sdk/transport.py index 72bab1f..904bba9 100644 --- a/src/fr24sdk/transport.py +++ b/src/fr24sdk/transport.py @@ -9,6 +9,7 @@ import httpx +from . import __version__ from .exceptions import ( ApiError, AuthenticationError, @@ -25,6 +26,7 @@ DEFAULT_BASE_URL = "https://fr24api.flightradar24.com" DEFAULT_API_VERSION = "v1" DEFAULT_TIMEOUT_SECONDS = 30 +DEFAULT_USER_AGENT = f"FR24 API Python SDK/{__version__}" class HttpTransport: @@ -57,6 +59,7 @@ def _get_default_headers(self) -> dict[str, str]: headers = { "Accept": "application/json", "Accept-Version": self.api_version, + "User-Agent": DEFAULT_USER_AGENT, } if self.api_token: headers["Authorization"] = f"Bearer {self.api_token}" diff --git a/tests/unit/test_transport.py b/tests/unit/test_transport.py index 03e02be..88aa6ff 100644 --- a/tests/unit/test_transport.py +++ b/tests/unit/test_transport.py @@ -14,6 +14,7 @@ DEFAULT_BASE_URL, DEFAULT_API_VERSION, DEFAULT_TIMEOUT_SECONDS, + DEFAULT_USER_AGENT, ) from fr24sdk.exceptions import ( ApiError, @@ -122,6 +123,7 @@ def test_default_headers(transport: HttpTransport) -> None: headers = transport._get_default_headers() assert headers["Accept"] == "application/json" assert headers["Accept-Version"] == DEFAULT_API_VERSION + assert headers["User-Agent"] == DEFAULT_USER_AGENT assert headers["Authorization"] == f"Bearer {TEST_TOKEN}" @@ -170,6 +172,7 @@ def test_request_with_params_and_custom_headers() -> None: # Removed respx_rout sent_headers = route.calls.last.request.headers assert sent_headers["x-custom-header"] == "custom_value" assert sent_headers["accept"] == "application/json" + assert sent_headers["user-agent"] == DEFAULT_USER_AGENT assert sent_headers["authorization"] == f"Bearer {TEST_TOKEN}"