This commit is contained in:
-LAN- 2026-03-01 03:36:03 -08:00 committed by GitHub
commit 5a112e0c54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 3 deletions

View File

@ -208,7 +208,7 @@ def encode_request(
if content is not None:
return encode_content(content)
elif files:
elif files is not None:
return encode_multipart_data(data or {}, files, boundary)
elif data:
return encode_urlencoded_data(data)

View File

@ -483,7 +483,7 @@ def main(
params=list(params),
content=content,
data=dict(data),
files=files, # type: ignore
files=files or None, # type: ignore
json=json,
headers=headers,
cookies=dict(cookies),

View File

@ -344,7 +344,7 @@ async def test_multipart_data_and_files_content():
@pytest.mark.anyio
async def test_empty_request():
request = httpx.Request(method, url, data={}, files={})
request = httpx.Request(method, url, data={})
assert isinstance(request.stream, typing.Iterable)
assert isinstance(request.stream, typing.AsyncIterable)
@ -516,3 +516,13 @@ def test_allow_nan_false():
ValueError, match="Out of range float values are not JSON compliant"
):
httpx.Response(200, json=data_with_inf)
def test_encode_request_with_data_and_empty_files():
request = httpx.Request(
url="https://www.example.com", method="POST", data={"key": "value"}, files={}
)
assert request.headers["Content-Type"].startswith("multipart/form-data; boundary=")
request.read()
assert b'Content-Disposition: form-data; name="key"' in request.content
assert b"value" in request.content