Skip to content

Commit 2a5d531

Browse files
fix(client): don't send Content-Type header on GET requests
1 parent b09f1ad commit 2a5d531

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Homepage = "https://github.com/isaacus-dev/isaacus-python"
3939
Repository = "https://github.com/isaacus-dev/isaacus-python"
4040

4141
[project.optional-dependencies]
42-
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]
42+
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.8"]
4343

4444
[tool.rye]
4545
managed = true

src/isaacus/_base_client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,15 @@ def _build_request(
504504
# work around https://github.com/encode/httpx/discussions/2880
505505
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
506506

507+
is_body_allowed = options.method.lower() != "get"
508+
509+
if is_body_allowed:
510+
kwargs["json"] = json_data if is_given(json_data) else None
511+
kwargs["files"] = files
512+
else:
513+
headers.pop("Content-Type", None)
514+
kwargs.pop("data", None)
515+
507516
# TODO: report this error to httpx
508517
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
509518
headers=headers,
@@ -515,8 +524,6 @@ def _build_request(
515524
# so that passing a `TypedDict` doesn't cause an error.
516525
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
517526
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
518-
json=json_data if is_given(json_data) else None,
519-
files=files,
520527
**kwargs,
521528
)
522529

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ def test_request_extra_query(self) -> None:
462462
def test_multipart_repeating_array(self, client: Isaacus) -> None:
463463
request = client._build_request(
464464
FinalRequestOptions.construct(
465-
method="get",
465+
method="post",
466466
url="/foo",
467467
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
468468
json_data={"array": ["foo", "bar"]},
@@ -1285,7 +1285,7 @@ def test_request_extra_query(self) -> None:
12851285
def test_multipart_repeating_array(self, async_client: AsyncIsaacus) -> None:
12861286
request = async_client._build_request(
12871287
FinalRequestOptions.construct(
1288-
method="get",
1288+
method="post",
12891289
url="/foo",
12901290
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
12911291
json_data={"array": ["foo", "bar"]},

0 commit comments

Comments
 (0)