Skip to content

Commit 730bf56

Browse files
author
piexlmax
committed
日志中间件对于上传文件做body过滤处理
1 parent 7473cdf commit 730bf56

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/middleware/operation.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ func OperationRecord() gin.HandlerFunc {
6464
Body: string(body),
6565
UserID: userId,
6666
}
67-
// 存在某些未知错误 TODO
68-
//values := c.Request.Header.Values("content-type")
69-
//if len(values) >0 && strings.Contains(values[0], "boundary") {
70-
// record.Body = "file"
71-
//}
67+
// 上传文件时候 中间件日志进行裁断操作
68+
if strings.Index(c.GetHeader("Content-Type"), "multipart/form-data") > -1 {
69+
if len(record.Body) > 512 {
70+
record.Body = "File or Length out of limit"
71+
}
72+
}
7273
writer := responseBodyWriter{
7374
ResponseWriter: c.Writer,
7475
body: &bytes.Buffer{},

0 commit comments

Comments
 (0)