fix: prevent nil pointer panic in PostForm getters when Context has no request

This commit is contained in:
water 2026-07-31 21:23:02 +08:00
parent 34dac209ff
commit 0e1e6d6ee8

View File

@ -647,14 +647,18 @@ func (c *Context) PostFormArray(key string) (values []string) {
func (c *Context) initFormCache() {
if c.formCache == nil {
c.formCache = make(url.Values)
req := c.Request
if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
if !errors.Is(err, http.ErrNotMultipart) {
debugPrint("error on parse multipart form array: %v", err)
if c.Request != nil {
c.formCache = make(url.Values)
req := c.Request
if err := req.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
if !errors.Is(err, http.ErrNotMultipart) {
debugPrint("error on parse multipart form array: %v", err)
}
}
c.formCache = req.PostForm
} else {
c.formCache = url.Values{}
}
c.formCache = req.PostForm
}
}