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.34k stars 255 forks source link

[BUG] Bytes data is sent as "application/x-www-form-urlencoded" #379

Closed vevv closed 1 month ago

vevv commented 1 month ago

Describe the bug Raw byte data provided with data= to requests.post has header application/x-www-form-urlencoded. This is not desireable as some servers will refuse a request with that header

To Reproduce

from curl_cffi import requests
resp = requests.post('https://httpbin.org/anything', data=b'test')

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

Expected behavior Should be application/octet-stream unless specified otherwise.

Requests only applies this header to types other than str and bytes (e.g. dict). https://github.com/psf/requests/blob/f12ccbef6d6b95564da8d22e280d28c39d53f0e9/src/requests/models.py#L552-L562

Versions

Additional context

https://github.com/lexiforest/curl_cffi/blob/8e69ad74f6fbff2a58148f0712c8f2247517e366/curl_cffi/requests/session.py#L450-L454C64