Skip to content

Commit 0a2a144

Browse files
Correct authorization to use Api-Key
- Updated client and tests to use `Api-Key` as the header name for API key injection. - Refactored default headers construction to reflect this change. - Modified related test assertions to validate the new header semantics. Assisted-by: Codex
1 parent d1fbac9 commit 0a2a144

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/pdfrest/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
DEFAULT_BASE_URL = "https://api.pdfrest.com"
2727
API_KEY_ENV_VAR = "PDFREST_API_KEY"
28+
API_KEY_HEADER_NAME = "Api-Key"
2829
DEFAULT_TIMEOUT_SECONDS = 10.0
2930
FILE_UPLOAD_FIELD_NAME = "file"
3031
DEFAULT_FILE_INFO_CONCURRENCY = 8
@@ -201,7 +202,7 @@ def __init__(
201202

202203
default_headers: dict[str, str] = {"Accept": "application/json"}
203204
if resolved_api_key is not None:
204-
default_headers["Authorization"] = f"Bearer {resolved_api_key}"
205+
default_headers[API_KEY_HEADER_NAME] = resolved_api_key
205206
if headers:
206207
for key, value in headers.items():
207208
default_headers[str(key)] = str(value)

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def pdfrest_api_key() -> str:
2222

2323
@pytest.fixture(scope="session")
2424
def pdfrest_live_base_url(pdfrest_api_key: str) -> str:
25-
headers = {"Authorization": f"Bearer {pdfrest_api_key}"}
25+
headers = {"Api-Key": pdfrest_api_key}
2626
timeout = httpx.Timeout(2.0)
2727
for base_url in LIVE_BASE_URL_CANDIDATES:
2828
try:

tests/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_client_uses_provided_api_key(monkeypatch: pytest.MonkeyPatch) -> None:
3434
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
3535

3636
def handler(request: httpx.Request) -> httpx.Response:
37-
assert request.headers["Authorization"] == f"Bearer {VALID_API_KEY}"
37+
assert request.headers["Api-Key"] == VALID_API_KEY
3838
assert request.url.path == "/up"
3939
return httpx.Response(200, json=_build_up_response())
4040

@@ -53,7 +53,7 @@ def test_client_reads_api_key_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
5353
monkeypatch.setenv("PDFREST_API_KEY", VALID_API_KEY)
5454

5555
def handler(request: httpx.Request) -> httpx.Response:
56-
assert request.headers["Authorization"] == f"Bearer {VALID_API_KEY}"
56+
assert request.headers["Api-Key"] == VALID_API_KEY
5757
assert request.url.host == "example.com"
5858
return httpx.Response(200, json=_build_up_response())
5959

@@ -95,7 +95,7 @@ def test_client_allows_missing_api_key_for_custom_host(
9595
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
9696

9797
def handler(request: httpx.Request) -> httpx.Response:
98-
assert "Authorization" not in request.headers
98+
assert "Api-Key" not in request.headers
9999
assert request.url.host == "internal.example"
100100
return httpx.Response(200, json=_build_up_response())
101101

@@ -113,7 +113,7 @@ def test_up_with_custom_headers(monkeypatch: pytest.MonkeyPatch) -> None:
113113
monkeypatch.delenv("PDFREST_API_KEY", raising=False)
114114

115115
def handler(request: httpx.Request) -> httpx.Response:
116-
assert request.headers["Authorization"] == f"Bearer {ANOTHER_VALID_API_KEY}"
116+
assert request.headers["Api-Key"] == ANOTHER_VALID_API_KEY
117117
assert request.headers["X-Test-Header"] == "value"
118118
return httpx.Response(200, json=_build_up_response())
119119

@@ -252,7 +252,7 @@ async def test_async_client_up(monkeypatch: pytest.MonkeyPatch) -> None:
252252
monkeypatch.setenv("PDFREST_API_KEY", ASYNC_API_KEY)
253253

254254
def handler(request: httpx.Request) -> httpx.Response:
255-
assert request.headers["Authorization"] == f"Bearer {ASYNC_API_KEY}"
255+
assert request.headers["Api-Key"] == ASYNC_API_KEY
256256
return httpx.Response(200, json=_build_up_response())
257257

258258
transport = httpx.MockTransport(handler)

0 commit comments

Comments
 (0)