Skip to content
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

Fix array encoding in form data requests #2060

Merged
merged 4 commits into from
Jun 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid reflection for processing arrays in form data
  • Loading branch information
Ivan Mirić committed Jun 15, 2021
commit c7bb596a530df5bb88e6336ebe4f9a946b7fae0e
13 changes: 5 additions & 8 deletions js/modules/k6/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,13 @@ func (h *HTTP) parseRequest(
if !requestContainsFile(data) {
bodyQuery := make(url.Values, len(data))
for k, v := range data {
switch reflect.TypeOf(v).Kind() { //nolint:exhaustive
// handle json arrays in params
case reflect.Slice, reflect.Array:
s := reflect.ValueOf(v)
for i := 0; i < s.Len(); i++ {
bodyQuery.Add(k, formatFormVal(s.Index(i)))
if arr, ok := v.([]interface{}); ok {
for _, el := range arr {
bodyQuery.Add(k, formatFormVal(el))
}
default:
bodyQuery.Set(k, formatFormVal(v))
continue
}
bodyQuery.Set(k, formatFormVal(v))
}
result.Body = bytes.NewBufferString(bodyQuery.Encode())
result.Req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
Expand Down