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.formCache == nil {
|
||||||
if c.MaxRequestBodySize > 0 {
|
if c.MaxRequestBodySize > 0 {
|
||||||
c.prepareRequestBody()
|
c.prepareRequestBody()
|
||||||
contentType := c.Request.Header.Get("Content-Type")
|
}
|
||||||
mediaType, _, err := mime.ParseMediaType(contentType)
|
contentType := c.Request.Header.Get("Content-Type")
|
||||||
if err != nil {
|
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.AddError(fmt.Errorf("parse form error: %w", err))
|
||||||
c.formCache = make(url.Values)
|
c.formCache = make(url.Values)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
case "application/x-www-form-urlencoded":
|
||||||
switch mediaType {
|
if err := c.Request.ParseForm(); err != nil {
|
||||||
case "multipart/form-data":
|
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||||
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
c.formCache = make(url.Values)
|
||||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
return ""
|
||||||
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 ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
if err := c.Request.ParseMultipartForm(defaultMemory); err != nil {
|
||||||
if !errors.Is(err, http.ErrNotMultipart) {
|
if !errors.Is(err, http.ErrNotMultipart) {
|
||||||
c.AddError(fmt.Errorf("parse form error: %w", err))
|
c.AddError(fmt.Errorf("parse form error: %w", err))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue