mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 01:20:55 +00:00
refactor: log error when payload too large
This commit is contained in:
parent
03f78b2e4a
commit
c3f14a0ad6
13
error.go
13
error.go
@ -363,12 +363,13 @@ func gatewayTimeout(rw http.ResponseWriter, r *http.Request) {
|
|||||||
func payloadTooLarge(rw http.ResponseWriter, r *http.Request) {
|
func payloadTooLarge(rw http.ResponseWriter, r *http.Request) {
|
||||||
responseError(rw, r,
|
responseError(rw, r,
|
||||||
413,
|
413,
|
||||||
"<br>The page you have requested is unavailable."+
|
`<br>The page you have requested is unavailable.
|
||||||
"<br>Perhaps you are here because:"+
|
<br>Perhaps you are here because:<br><br>
|
||||||
"<br><br><ul>"+
|
<ul>
|
||||||
"<br>The request entity is larger than limits defined by server"+
|
<br>The request entity is larger than limits defined by server.
|
||||||
"<br>Please change the request entity and try again."+
|
<br>Please change the request entity and try again.
|
||||||
"</ul>",
|
</ul>
|
||||||
|
`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,7 +707,9 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||||
if BConfig.CopyRequestBody && !context.Input.IsUpload() {
|
if BConfig.CopyRequestBody && !context.Input.IsUpload() {
|
||||||
|
// connection will close if the incoming data are larger (RFC 7231, 6.5.11)
|
||||||
if r.ContentLength > BConfig.MaxMemory {
|
if r.ContentLength > BConfig.MaxMemory {
|
||||||
|
logs.Error(errors.New("payload too large"))
|
||||||
exception("413", context)
|
exception("413", context)
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
|
@ -726,7 +726,7 @@ func TestRouterEntityTooLargeCopyBody(t *testing.T) {
|
|||||||
BConfig.CopyRequestBody = _CopyRequestBody
|
BConfig.CopyRequestBody = _CopyRequestBody
|
||||||
BConfig.MaxMemory = _MaxMemory
|
BConfig.MaxMemory = _MaxMemory
|
||||||
|
|
||||||
if w.Code != 413 {
|
if w.Code != http.StatusRequestEntityTooLarge {
|
||||||
t.Errorf("TestRouterRequestEntityTooLarge can't run")
|
t.Errorf("TestRouterRequestEntityTooLarge can't run")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user