valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.66k stars 1.75k forks source link

Ordering of HTTP headers #1572

Closed antter closed 1 year ago

antter commented 1 year ago

Hi, I have a bit of an odd complaint. I originally turned to this package because you can control the case and ordering of headers, which is not possible with net/http.

As I had come to find out, even when SetCanonical is used, the User-Agent header always comes before Host. Headers re-ordering is a problem for proxies avoiding bot detection. In my case I am working on a proxy for intercepting traffic for web debugging. I end up sending out requests that starts with

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/113.0
Host: google.com

Even though Firefox would never put the User-Agent before Host.

erikdubbelboer commented 1 year ago

I'm afraid that this is not possible with fasthttp. fasthttp stores some headers into internal variables and will always write them in the same order as seen here: https://github.com/valyala/fasthttp/blob/f0865d4aabbbea51a81d56ab31a3de2dfc5a9b05/header.go#L2473-L2492 There is currently no way to change that. If you want to make a pull request to add support for this it would be welcome, but only if it doesn't affect performance.