Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/fr24sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import httpx

from . import __version__
from .exceptions import (
ApiError,
AuthenticationError,
Expand All @@ -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:
Expand Down Expand Up @@ -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}"
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DEFAULT_BASE_URL,
DEFAULT_API_VERSION,
DEFAULT_TIMEOUT_SECONDS,
DEFAULT_USER_AGENT,
)
from fr24sdk.exceptions import (
ApiError,
Expand Down Expand Up @@ -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}"


Expand Down Expand Up @@ -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}"


Expand Down
Loading