From bf666adcd8cee994461229e29c9d3f69b9286a0a Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Tue, 17 Nov 2026 16:38:24 +0100 Subject: [PATCH] feat: send the X-Capawesome-Client header Every request now sends `X-Capawesome-Client: cloud-python/`, also on a caller-supplied `httpx.Client`. The `User-Agent` stays as before. Co-Authored-By: Claude Opus 5.5 --- src/capawesome_cloud/_http.py | 5 +++-- tests/test_client.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/capawesome_cloud/_http.py b/src/capawesome_cloud/_http.py index b10c362..ecbcf46 100644 --- a/src/capawesome_cloud/_http.py +++ b/src/capawesome_cloud/_http.py @@ -62,9 +62,10 @@ def __init__( base_url=base_url.rstrip("/"), timeout=timeout, ) - # The token must always apply; identify ourselves on clients we create - # without clobbering a caller-supplied client's User-Agent. + # The token and the client header must always apply. The User-Agent is + # set only on clients we create, so a caller-supplied one keeps its own. self._client.headers["Authorization"] = f"Bearer {token}" + self._client.headers["X-Capawesome-Client"] = f"cloud-python/{__version__}" self._client.headers.setdefault("Accept", "application/json") if self._owns_client: self._client.headers["User-Agent"] = f"capawesome-cloud-python/{__version__}" diff --git a/tests/test_client.py b/tests/test_client.py index 43b5a28..f929526 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -3,7 +3,7 @@ import httpx import pytest -from capawesome_cloud import CapawesomeCloud, CapawesomeCloudError +from capawesome_cloud import CapawesomeCloud, CapawesomeCloudError, __version__ def test_token_from_env(monkeypatch: pytest.MonkeyPatch) -> None: @@ -41,11 +41,12 @@ def test_missing_token_raises(monkeypatch: pytest.MonkeyPatch) -> None: CapawesomeCloud(token=" ") -def test_sets_auth_and_user_agent_headers() -> None: +def test_sets_auth_and_client_headers() -> None: client = CapawesomeCloud(token="abc") headers = client._http._client.headers assert headers["Authorization"] == "Bearer abc" - assert headers["User-Agent"].startswith("capawesome-cloud-python/") + assert headers["User-Agent"] == f"capawesome-cloud-python/{__version__}" + assert headers["X-Capawesome-Client"] == f"cloud-python/{__version__}" def test_context_manager_closes() -> None: