remove file and form from log

This commit is contained in:
YouROK
2021-04-28 16:06:49 +03:00
parent f6f1ddc952
commit 5b1ea6fb24

View File

@@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@@ -75,8 +76,14 @@ func WebLogger() gin.HandlerFunc {
c.Next() c.Next()
return return
} }
body := ""
//save body if not form or file
if !strings.HasPrefix(c.Request.Header.Get("Content-Type"), "multipart/form-data") {
body, _ := ioutil.ReadAll(c.Request.Body) body, _ := ioutil.ReadAll(c.Request.Body)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body)) c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(body))
} else {
body = "body hidden, too large"
}
c.Next() c.Next()
statusCode := c.Writer.Status() statusCode := c.Writer.Status()