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.44k stars 263 forks source link

[BUG] Request headers not set in the response #368

Open IV1T3 opened 3 months ago

IV1T3 commented 3 months ago

Describe the bug The request headers are not set in the response object. As shown in the example below, even though request headers were sent, the Headers object is empty in the response.

To Reproduce

>>> from curl_cffi import requests
>>> res = requests.get("https://httpbin.org/headers")
>>> res.json()
{'headers': {'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br, zstd', 'Host': 'httpbin.org', 'X-Amzn-Trace-Id': 'Root=1-66b8ff1e-50969ef8662112f677a6f081'}}
>>> res.request.__dict__
{'url': 'https://httpbin.org/headers', 'headers': Headers({}), 'method': 'GET'}

This also happens using a Session

Expected behavior I expect the headers to be set.

Versions

perklet commented 3 months ago

Indeed, will fix later. However, avoid using __dict__ if it's not for demostration here.

lexiforest commented 1 month ago

Actually, there is no API in libcurl for reading these builtin headers. I will need to patch curl itself to retrieve these values, please expect a longer fix time.