lexiforest / curl_cffi

Python binding for curl-impersonate fork via cffi. A http client that can impersonate browser tls/ja3/http2 fingerprints.
https://curl-cffi.readthedocs.io/
MIT License
2.51k stars 266 forks source link

[BUG] Explicit Content-Type is being overwritten #403

Closed vevv closed 1 month ago

vevv commented 1 month ago

Describe the bug curl_cffi still messes with Content-Type headers. Even If I set Content-Type to "text/plain" manually, and send a POST request with string data, it will be encoded with "application/octet-stream".

To Reproduce

from curl_cffi import requests

resp = requests.post(url="https://httpbin.dev/headers", data="test", headers={"Content-Type": "text/plain"})

print(resp.json()["headers"]["Content-Type"])

Expected behavior User-provided Content-Type headers are expected.

Versions

Additional Context Unrelated, but this part is incorrect:

if isinstance(data, dict) and method != "POST":
    _update_header_line(header_lines, "Content-Type", "application/x-www-form-urlencoded")

This should run on POST as well, it's usually used with POST or PUT.

Also, "text/plain" is probably more appropriate for strings.

lexiforest commented 1 month ago

Duplicate of #395, fixed in v0.7.3