Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
二次元的罪恶王冠
beego
提交
946a42c0
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,发现更多精彩内容 >>
未验证
提交
946a42c0
编写于
7月 08, 2020
作者:
C
Chenrui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: response http 413 when body size larger then MaxMemory.
上级
bac2b31a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
4 deletion
+29
-4
router.go
router.go
+4
-0
router_test.go
router_test.go
+25
-4
未找到文件。
router.go
浏览文件 @
946a42c0
...
...
@@ -707,6 +707,10 @@ 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
()
{
if
r
.
ContentLength
>
BConfig
.
MaxMemory
{
exception
(
"413"
,
context
)
goto
Admin
}
context
.
Input
.
CopyBody
(
BConfig
.
MaxMemory
)
}
context
.
Input
.
ParseFormOrMulitForm
(
BConfig
.
MaxMemory
)
...
...
router_test.go
浏览文件 @
946a42c0
...
...
@@ -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
!=
413
{
t
.
Errorf
(
"TestRouterRequestEntityTooLarge can't run"
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录