Skip to content

Commit

Permalink
httpx initial client headers are respected and merged
Browse files Browse the repository at this point in the history
  • Loading branch information
foarsitter committed Feb 11, 2024
1 parent 1a52f45 commit cd370bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/requestmodel/adapters/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def transform(
) -> Request:
request_args = model.request_args_for_values()

headers = request_args[params.Header]
headers = client.headers

if request_args[params.Header]:
headers.update(request_args[params.Header])

body = request_args[params.Body]

is_json_request = "json" in headers.get("content-type", "")
Expand Down
11 changes: 11 additions & 0 deletions tests/test_httpx_adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from httpx import Client

from tests.locatieserver.requests import LookupRequest


def test_preserve_header() -> None:
client = Client(headers={"X-Test": "test"})

request = LookupRequest(id="test").as_request(client)

assert request.headers["X-Test"] == "test"

0 comments on commit cd370bd

Please sign in to comment.