-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ordered form data #391
Comments
Good idea, will implement it when I have time |
imroc
added a commit
that referenced
this issue
Oct 10, 2024
Released in v3.47.0 Runnable demo: package main
import (
"github.com/imroc/req/v3"
)
func main() {
req.DevMode()
req.R().
// EnableForceMultipart().
SetOrderedFormData(
"key3", "value3",
"key1", "value1",
"key2", "value2",
).Post("https://httpbin.org/post")
} |
Thanks, that was really quick! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the moment form data is always sorted alphabetically, because
map
andnet/url.Values
sort keys alphabetically (see this issue). However, most browsers send form data in the order in which it appears in the submitted form. This poses an issue when attempting to mimic browser behavior (usingclient.ImpersonateChrome
orclient.ImpersonateFirefox
) as alphabetically ordered form data can be detected as anomalous, particularly when every other request is honoring the original form order.My suggestion would be to add
request.SetOrderedFormData
andclient.SetCommonOrderedFormData
methods, which accept an ordered map (for example this one) as an argument and set theOrderedFormData
field of the request or client respectively. Unfortunately this could create confusion over whetherFormData
orOrderedFormData
takes precedence when both are set. Changing the type of theFormData
field fromnet/url.Values
to an ordered map would solve this problem, but would break things for anyone relying onFormData
to be of the typenet/url.Values
.The text was updated successfully, but these errors were encountered: