diff --git a/net/ghttp/ghttp_request_param.go b/net/ghttp/ghttp_request_param.go index aaa873468..cf232c4d7 100644 --- a/net/ghttp/ghttp_request_param.go +++ b/net/ghttp/ghttp_request_param.go @@ -269,8 +269,14 @@ func (r *Request) parseForm() { return } if contentType := r.Header.Get("Content-Type"); contentType != "" { - var err error + var ( + err error + repeatableRead = true + ) if gstr.Contains(contentType, "multipart/") { + // To avoid big memory consuming. + // The `multipart/` type form always contains binary data, which is not necessary read twice. + repeatableRead = false // multipart/form-data, multipart/mixed if err = r.ParseMultipartForm(r.Server.config.FormParsingMemory); err != nil { panic(gerror.WrapCode(gcode.CodeInvalidRequest, err, "r.ParseMultipartForm failed")) @@ -281,6 +287,9 @@ func (r *Request) parseForm() { panic(gerror.WrapCode(gcode.CodeInvalidRequest, err, "r.Request.ParseForm failed")) } } + if repeatableRead { + r.MakeBodyRepeatableRead(true) + } if len(r.PostForm) > 0 { // Parse the form data using united parsing way. params := "" diff --git a/util/gconv/gconv_map.go b/util/gconv/gconv_map.go index 33470ebd0..904debeef 100644 --- a/util/gconv/gconv_map.go +++ b/util/gconv/gconv_map.go @@ -52,6 +52,7 @@ func Map(value interface{}, option ...MapOption) map[string]interface{} { // Deprecated: used Map instead. func MapDeep(value interface{}, tags ...string) map[string]interface{} { return doMapConvert(value, recursiveTypeTrue, false, MapOption{ + Deep: true, Tags: tags, }) }