client: retain order of headers in requests as specified #1518
+108
−65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As a side effect of how fasthttp handles custom headers, retaining the order of entries is already possible for most headers specified, however - and this is problematic for very old web servers that expect headers to be sent in a specific order - certain headers, such as
Host
andUser-Agent
can't be reordered due to how those are handled in a special way. This proposed change makes sure that if such headers are specified usingr.Header.Set("Host", "foo")
andr.Header.Set("User-Agent", "bar")
, the correct order of headers is retained.This change implements a behavior that was requested multiple times by different people in the standard
net/http
package:Since the Golang maintainers have no interest in implementing this behavior or even accept an already fully functional proposed change, I've started using fasthttp and implementing this behavior into the library for myself and others to use.
Example code:
Header sent with the current behavior:
Header sent with the new behavior: