Add GetPostFormData to return c.formCache

This commit is contained in:
Awezome 2021-12-17 11:46:41 +08:00
parent fb5f045417
commit d76523415c
2 changed files with 10 additions and 0 deletions

View File

@ -547,6 +547,13 @@ func (c *Context) GetPostFormMap(key string) (map[string]string, bool) {
return c.get(c.formCache, key) return c.get(c.formCache, key)
} }
// GetPostFormData returns c.formCache, which cached PostForm contains the parsed form data from POST, PATCH,
// or PUT body parameters.
func (c *Context) GetPostFormData() url.Values {
c.initFormCache()
return c.formCache
}
// get is an internal method and returns a map which satisfy conditions. // get is an internal method and returns a map which satisfy conditions.
func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) { func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) {
dicts := make(map[string]string) dicts := make(map[string]string)

View File

@ -608,6 +608,9 @@ func TestContextPostFormMultipart(t *testing.T) {
dicts = c.PostFormMap("nokey") dicts = c.PostFormMap("nokey")
assert.Equal(t, 0, len(dicts)) assert.Equal(t, 0, len(dicts))
formData := c.GetPostFormData()
assert.Equal(t, 9, len(formData))
} }
func TestContextSetCookie(t *testing.T) { func TestContextSetCookie(t *testing.T) {