diff --git a/middleware.go b/middleware.go index 333be41d..a6b087f5 100644 --- a/middleware.go +++ b/middleware.go @@ -424,24 +424,19 @@ func handleMultipart(c *Client, r *Request) (err error) { func handleFormData(c *Client, r *Request) { formData := url.Values{} - - for k, v := range c.FormData { - for _, iv := range v { - formData.Add(k, iv) - } - } - for k, v := range r.FormData { - // remove form data field from client level by key - // since overrides happens for that key in the request - formData.Del(k) + formData[k] = v[:] + } - for _, iv := range v { - formData.Add(k, iv) + for k, v := range c.FormData { + if _, ok := formData[k]; ok { + continue } + formData[k] = v[:] } - r.bodyBuf = bytes.NewBuffer([]byte(formData.Encode())) + r.bodyBuf = acquireBuffer() + r.bodyBuf.WriteString(formData.Encode()) r.Header.Set(hdrContentTypeKey, formContentType) r.isFormData = true }