body size middleware for public POST endpoints

This commit is contained in:
Riccardo Berto 2021-05-27 21:27:56 +02:00
parent e30488eb1f
commit 619011311a

View File

@ -0,0 +1,16 @@
package controller
import (
"net/http"
"github.com/gin-gonic/gin"
)
const maxBodyBytes = int64(65536)
func bodySizeMiddleware(c *gin.Context) {
var w http.ResponseWriter = c.Writer
c.Request.Body = http.MaxBytesReader(w, c.Request.Body, maxBodyBytes)
c.Next()
}