From d76523415c2e8e650fdd56f5ddc4fa888a7f1ba5 Mon Sep 17 00:00:00 2001 From: Awezome Date: Fri, 17 Dec 2021 11:46:41 +0800 Subject: [PATCH] Add GetPostFormData to return c.formCache --- context.go | 7 +++++++ context_test.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/context.go b/context.go index 4fb3ae6d..e0355f69 100644 --- a/context.go +++ b/context.go @@ -547,6 +547,13 @@ func (c *Context) GetPostFormMap(key string) (map[string]string, bool) { 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. func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) { dicts := make(map[string]string) diff --git a/context_test.go b/context_test.go index 4d002c23..632046da 100644 --- a/context_test.go +++ b/context_test.go @@ -608,6 +608,9 @@ func TestContextPostFormMultipart(t *testing.T) { dicts = c.PostFormMap("nokey") assert.Equal(t, 0, len(dicts)) + + formData := c.GetPostFormData() + assert.Equal(t, 9, len(formData)) } func TestContextSetCookie(t *testing.T) {