Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

461 B
Raw Blame
package middleware

import (
	"net/http"

	"github.com/ente/museum/pkg/utils/handler"
	"github.com/gin-gonic/gin"
)

const maxRequestBodySize = 4 << 20

func LimitRequestBody() gin.HandlerFunc {
	return func(c *gin.Context) {
		if c.Request.ContentLength > maxRequestBodySize {
			handler.Error(c, &http.MaxBytesError{Limit: maxRequestBodySize})
			return
		}
		c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxRequestBodySize)
		c.Next()
	}
}