Skip to content

Commit f8aaafa

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

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
@@ -45,7 +45,7 @@ Homepage = "https://github.com/openlayer-ai/openlayer-python"
4545
Repository = "https://github.com/openlayer-ai/openlayer-python"
4646

4747
[project.optional-dependencies]
48-
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]
48+
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.8"]
4949

5050
[tool.rye]
5151
managed = true

src/openlayer/_base_client.py

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

532+
is_body_allowed = options.method.lower() != "get"
533+
534+
if is_body_allowed:
535+
kwargs["json"] = json_data if is_given(json_data) else None
536+
kwargs["files"] = files
537+
else:
538+
headers.pop("Content-Type", None)
539+
kwargs.pop("data", None)
540+
532541
# TODO: report this error to httpx
533542
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
534543
headers=headers,
@@ -540,8 +549,6 @@ def _build_request(
540549
# so that passing a `TypedDict` doesn't cause an error.
541550
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
542551
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
543-
json=json_data if is_given(json_data) else None,
544-
files=files,
545552
**kwargs,
546553
)
547554

tests/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def test_request_extra_query(self) -> None:
473473
def test_multipart_repeating_array(self, client: Openlayer) -> None:
474474
request = client._build_request(
475475
FinalRequestOptions.construct(
476-
method="get",
476+
method="post",
477477
url="/foo",
478478
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
479479
json_data={"array": ["foo", "bar"]},
@@ -1355,7 +1355,7 @@ def test_request_extra_query(self) -> None:
13551355
def test_multipart_repeating_array(self, async_client: AsyncOpenlayer) -> None:
13561356
request = async_client._build_request(
13571357
FinalRequestOptions.construct(
1358-
method="get",
1358+
method="post",
13591359
url="/foo",
13601360
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
13611361
json_data={"array": ["foo", "bar"]},

0 commit comments

Comments
 (0)