mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
fix(form): align PostForm parsing with body limit handling
This commit is contained in:
parent
64e2ad9e7b
commit
85cc9b5cf6
1 changed files with 18 additions and 18 deletions
36
context.go
36
context.go
|
|
@ -275,29 +275,29 @@ func (c *Context) PostForm(key string) string {
|
|||
if c.formCache == nil {
|
||||
if c.MaxRequestBodySize > 0 {
|
||||
c.prepareRequestBody()
|
||||
contentType := c.Request.Header.Get("Content-Type")
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
}
|
||||
contentType := c.Request.Header.Get("Content-Type")
|
||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
||||
if err != nil {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
c.formCache = make(url.Values)
|
||||
return ""
|
||||
}
|
||||
|
||||
switch mediaType {
|
||||
case "multipart/form-data":
|
||||
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
c.formCache = make(url.Values)
|
||||
return ""
|
||||
}
|
||||
|
||||
switch mediaType {
|
||||
case "multipart/form-data":
|
||||
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
c.formCache = make(url.Values)
|
||||
return ""
|
||||
}
|
||||
default:
|
||||
if err := c.Request.ParseForm(); err != nil {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
c.formCache = make(url.Values)
|
||||
return ""
|
||||
}
|
||||
case "application/x-www-form-urlencoded":
|
||||
if err := c.Request.ParseForm(); err != nil {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
c.formCache = make(url.Values)
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
||||
if !errors.Is(err, http.ErrNotMultipart) {
|
||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue