This commit is contained in:
John Guo
2024-01-17 15:35:48 +08:00
committed by GitHub
parent d26b7c5437
commit 951f8921cd
2 changed files with 11 additions and 1 deletions

View File

@ -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 := ""

View File

@ -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,
})
}