yifeikong / curl_cffi

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

[Feature] Respect headers order with the built-in requests #335

Open Tagge opened 3 days ago

Tagge commented 3 days ago

Is your feature request related to a problem? Please describe. In some special instances, I have to be able to specify the order of my HTTP headers. Usually, with the original requests library, I would be able to do that by passing it an instance of Collections.OrderedDict containing my headers in the order desired. I have tried this approach with curl_cffi, and it doesn't seem to conserve the order of the headers no matter what I do. This is a useful feature as an order can sometimes be imposed by the webserver.

Describe the solution you'd like Like for the requests library, it would be ideal to be able to pass an OrderedDict object that would automatically trigger the ordering of the headers.

Describe alternatives you've considered Sadly, in those instances, I am forced to use something else.

yifeikong commented 3 days ago

Did you use the default_headers=False option to disable built-in headers? They may interfere with your custom headers.

Tagge commented 3 days ago

Sadly it doesn't change it. Host is still being moved to the very top, and Accept is added automatically.

yifeikong commented 3 days ago

I see. Host being reordered is a known issue. Are there any other headers that jump around unexpectedly? except for Host and Accept.

I will update the progress in this issue.

Tagge commented 3 days ago

In my case, Accept-Encoding also has been swapped with Connection. I think it's mostly those ones.