mirror of
https://github.com/anomalyco/opencode-sdk-python.git
synced 2026-05-06 08:22:07 +00:00
fix(client): don't send Content-Type header on GET requests
This commit is contained in:
parent
63b90c4351
commit
54b122ff18
3 changed files with 12 additions and 5 deletions
|
|
@ -39,7 +39,7 @@ Homepage = "https://github.com/sst/opencode-sdk-python"
|
|||
Repository = "https://github.com/sst/opencode-sdk-python"
|
||||
|
||||
[project.optional-dependencies]
|
||||
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.6"]
|
||||
aiohttp = ["aiohttp", "httpx_aiohttp>=0.1.8"]
|
||||
|
||||
[tool.rye]
|
||||
managed = true
|
||||
|
|
|
|||
|
|
@ -529,6 +529,15 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|||
# work around https://github.com/encode/httpx/discussions/2880
|
||||
kwargs["extensions"] = {"sni_hostname": prepared_url.host.replace("_", "-")}
|
||||
|
||||
is_body_allowed = options.method.lower() != "get"
|
||||
|
||||
if is_body_allowed:
|
||||
kwargs["json"] = json_data if is_given(json_data) else None
|
||||
kwargs["files"] = files
|
||||
else:
|
||||
headers.pop("Content-Type", None)
|
||||
kwargs.pop("data", None)
|
||||
|
||||
# TODO: report this error to httpx
|
||||
return self._client.build_request( # pyright: ignore[reportUnknownMemberType]
|
||||
headers=headers,
|
||||
|
|
@ -540,8 +549,6 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
|
|||
# so that passing a `TypedDict` doesn't cause an error.
|
||||
# https://github.com/microsoft/pyright/issues/3526#event-6715453066
|
||||
params=self.qs.stringify(cast(Mapping[str, Any], params)) if params else None,
|
||||
json=json_data if is_given(json_data) else None,
|
||||
files=files,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ class TestOpencode:
|
|||
def test_multipart_repeating_array(self, client: Opencode) -> None:
|
||||
request = client._build_request(
|
||||
FinalRequestOptions.construct(
|
||||
method="get",
|
||||
method="post",
|
||||
url="/foo",
|
||||
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
|
||||
json_data={"array": ["foo", "bar"]},
|
||||
|
|
@ -1203,7 +1203,7 @@ class TestAsyncOpencode:
|
|||
def test_multipart_repeating_array(self, async_client: AsyncOpencode) -> None:
|
||||
request = async_client._build_request(
|
||||
FinalRequestOptions.construct(
|
||||
method="get",
|
||||
method="post",
|
||||
url="/foo",
|
||||
headers={"Content-Type": "multipart/form-data; boundary=6b7ba517decee4a450543ea6ae821c82"},
|
||||
json_data={"array": ["foo", "bar"]},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue