Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom headers in multipart/form-data requests #1936

Merged
merged 15 commits into from Jan 13, 2022
Merged
5 changes: 3 additions & 2 deletions httpx/_multipart.py
Expand Up @@ -97,11 +97,12 @@ def __init__(self, name: str, value: FileTypes) -> None:
else:
filename = Path(str(getattr(value, "name", "upload"))).name
fileobj = value

tomchristie marked this conversation as resolved.
Show resolved Hide resolved
if content_type is None:
content_type = guess_content_type(filename)

if content_type is not None and "Content-Type" not in headers:
has_content_type_header = any("content-type" in key.lower() for key in headers)
if content_type is not None and not has_content_type_header:
# note that unlike requests, we ignore the content_type
# provided in the 3rd tuple element if it is also included in the headers
# requests does the opposite (it overwrites the header with the 3rd tuple element)
Expand Down