Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
35dcc3df
B
beego
项目概览
二次元的罪恶王冠
/
beego
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
beego
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
35dcc3df
编写于
7月 09, 2020
作者:
M
Ming Deng
提交者:
GitHub
7月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4058 from a631807682/fix/issues/4054
Fix response payload too large
上级
8ee167bc
c3f14a0a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
47 addition
and
5 deletion
+47
-5
error.go
error.go
+15
-1
hooks.go
hooks.go
+1
-0
router.go
router.go
+6
-0
router_test.go
router_test.go
+25
-4
未找到文件。
error.go
浏览文件 @
35dcc3df
...
...
@@ -28,7 +28,7 @@ import (
)
const
(
errorTypeHandler
=
iota
errorTypeHandler
=
iota
errorTypeController
)
...
...
@@ -359,6 +359,20 @@ func gatewayTimeout(rw http.ResponseWriter, r *http.Request) {
)
}
// show 413 Payload Too Large
func
payloadTooLarge
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
responseError
(
rw
,
r
,
413
,
`<br>The page you have requested is unavailable.
<br>Perhaps you are here because:<br><br>
<ul>
<br>The request entity is larger than limits defined by server.
<br>Please change the request entity and try again.
</ul>
`
,
)
}
func
responseError
(
rw
http
.
ResponseWriter
,
r
*
http
.
Request
,
errCode
int
,
errContent
string
)
{
t
,
_
:=
template
.
New
(
"beegoerrortemp"
)
.
Parse
(
errtpl
)
data
:=
M
{
...
...
hooks.go
浏览文件 @
35dcc3df
...
...
@@ -34,6 +34,7 @@ func registerDefaultErrorHandler() error {
"504"
:
gatewayTimeout
,
"417"
:
invalidxsrf
,
"422"
:
missingxsrf
,
"413"
:
payloadTooLarge
,
}
for
e
,
h
:=
range
m
{
if
_
,
ok
:=
ErrorMaps
[
e
];
!
ok
{
...
...
router.go
浏览文件 @
35dcc3df
...
...
@@ -742,6 +742,12 @@ func (p *ControllerRegister) ServeHTTP(rw http.ResponseWriter, r *http.Request)
if
r
.
Method
!=
http
.
MethodGet
&&
r
.
Method
!=
http
.
MethodHead
{
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
{
logs
.
Error
(
errors
.
New
(
"payload too large"
))
exception
(
"413"
,
context
)
goto
Admin
}
context
.
Input
.
CopyBody
(
BConfig
.
MaxMemory
)
}
context
.
Input
.
ParseFormOrMulitForm
(
BConfig
.
MaxMemory
)
...
...
router_test.go
浏览文件 @
35dcc3df
...
...
@@ -15,6 +15,7 @@
package
beego
import
(
"bytes"
"net/http"
"net/http/httptest"
"strings"
...
...
@@ -71,7 +72,6 @@ func (tc *TestController) GetEmptyBody() {
tc
.
Ctx
.
Output
.
Body
(
res
)
}
type
JSONController
struct
{
Controller
}
...
...
@@ -656,17 +656,14 @@ func beegoBeforeRouter1(ctx *context.Context) {
ctx
.
WriteString
(
"|BeforeRouter1"
)
}
func
beegoBeforeExec1
(
ctx
*
context
.
Context
)
{
ctx
.
WriteString
(
"|BeforeExec1"
)
}
func
beegoAfterExec1
(
ctx
*
context
.
Context
)
{
ctx
.
WriteString
(
"|AfterExec1"
)
}
func
beegoFinishRouter1
(
ctx
*
context
.
Context
)
{
ctx
.
WriteString
(
"|FinishRouter1"
)
}
...
...
@@ -709,3 +706,27 @@ func TestYAMLPrepare(t *testing.T) {
t
.
Errorf
(
w
.
Body
.
String
())
}
}
func
TestRouterEntityTooLargeCopyBody
(
t
*
testing
.
T
)
{
_MaxMemory
:=
BConfig
.
MaxMemory
_CopyRequestBody
:=
BConfig
.
CopyRequestBody
BConfig
.
CopyRequestBody
=
true
BConfig
.
MaxMemory
=
20
b
:=
bytes
.
NewBuffer
([]
byte
(
"barbarbarbarbarbarbarbarbarbar"
))
r
,
_
:=
http
.
NewRequest
(
"POST"
,
"/user/123"
,
b
)
w
:=
httptest
.
NewRecorder
()
handler
:=
NewControllerRegister
()
handler
.
Post
(
"/user/:id"
,
func
(
ctx
*
context
.
Context
)
{
ctx
.
Output
.
Body
([]
byte
(
ctx
.
Input
.
Param
(
":id"
)))
})
handler
.
ServeHTTP
(
w
,
r
)
BConfig
.
CopyRequestBody
=
_CopyRequestBody
BConfig
.
MaxMemory
=
_MaxMemory
if
w
.
Code
!=
http
.
StatusRequestEntityTooLarge
{
t
.
Errorf
(
"TestRouterRequestEntityTooLarge can't run"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录