feat: support form array in three notations (#4498)

Signed-off-by: kevin <wanjunfeng@gmail.com>
This commit is contained in:
Kevin Wan
2024-12-23 00:56:20 +08:00
committed by GitHub
parent 2159d112c3
commit 1d9159ea39
6 changed files with 452 additions and 81 deletions

View File

@@ -1,7 +1,9 @@
package httpx
import (
"fmt"
"net/http"
"net/url"
"strings"
"testing"
@@ -23,3 +25,23 @@ func TestGetRemoteAddrNoHeader(t *testing.T) {
assert.True(t, len(GetRemoteAddr(r)) == 0)
}
func TestGetFormValues_TooManyValues(t *testing.T) {
form := url.Values{}
// Add more values than the limit
for i := 0; i < maxFormParamCount+10; i++ {
form.Add("param", fmt.Sprintf("value%d", i))
}
// Create a new request with the form data
req, err := http.NewRequest("POST", "/test", strings.NewReader(form.Encode()))
assert.NoError(t, err)
// Set the content type for form data
req.Header.Set(ContentType, "application/x-www-form-urlencoded")
_, err = GetFormValues(req)
assert.Error(t, err)
assert.Contains(t, err.Error(), "too many form values")
}