mirror of
https://github.com/astaxie/beego.git
synced 2024-11-21 13:20:55 +00:00
Merge pull request #4272 from jianzhiyao/fix-4224
fix 4224:form entity too large casue run out of memory
This commit is contained in:
commit
f9075e8274
@ -266,7 +266,7 @@ func (input *BeegoInput) SetData(key, val interface{}) {
|
||||
|
||||
// ParseFormOrMulitForm parseForm or parseMultiForm based on Content-type
|
||||
func (input *BeegoInput) ParseFormOrMulitForm(maxMemory int64) error {
|
||||
return (*context.BeegoInput)(input).ParseFormOrMulitForm(maxMemory)
|
||||
return (*context.BeegoInput)(input).ParseFormOrMultiForm(maxMemory)
|
||||
}
|
||||
|
||||
// Bind data from request.Form[key] to dest
|
||||
|
@ -420,9 +420,10 @@ func (input *BeegoInput) SetData(key, val interface{}) {
|
||||
input.data[key] = val
|
||||
}
|
||||
|
||||
// ParseFormOrMulitForm parseForm or parseMultiForm based on Content-type
|
||||
func (input *BeegoInput) ParseFormOrMulitForm(maxMemory int64) error {
|
||||
// ParseFormOrMultiForm parseForm or parseMultiForm based on Content-type
|
||||
func (input *BeegoInput) ParseFormOrMultiForm(maxMemory int64) error {
|
||||
// Parse the body depending on the content type.
|
||||
input.Context.Request.Body = http.MaxBytesReader(input.Context.ResponseWriter, input.Context.Request.Body, maxMemory)
|
||||
if strings.Contains(input.Header("Content-Type"), "multipart/form-data") {
|
||||
if err := input.Context.Request.ParseMultipartForm(maxMemory); err != nil {
|
||||
return errors.New("Error parsing request body:" + err.Error())
|
||||
|
@ -666,6 +666,7 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
|
||||
var err error
|
||||
startTime := time.Now()
|
||||
r := ctx.Request
|
||||
rw := ctx.ResponseWriter.ResponseWriter
|
||||
@ -718,12 +719,21 @@ func (p *ControllerRegister) serveHttp(ctx *beecontext.Context) {
|
||||
}
|
||||
ctx.Input.CopyBody(p.cfg.MaxMemory)
|
||||
}
|
||||
ctx.Input.ParseFormOrMulitForm(p.cfg.MaxMemory)
|
||||
|
||||
err = ctx.Input.ParseFormOrMultiForm(p.cfg.MaxMemory)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
if strings.Contains(err.Error(), `http: request body too large`) {
|
||||
exception("413", ctx)
|
||||
} else {
|
||||
exception("500", ctx)
|
||||
}
|
||||
goto Admin
|
||||
}
|
||||
}
|
||||
|
||||
// session init
|
||||
if p.cfg.WebConfig.Session.SessionOn {
|
||||
var err error
|
||||
ctx.Input.CruSession, err = GlobalSessions.SessionStart(rw, r)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
|
Loading…
Reference in New Issue
Block a user