remove check body

This commit is contained in:
celogeek 2022-05-09 09:48:26 +02:00
parent 8c6ef9c3cc
commit 9934ef91c0
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A
3 changed files with 9 additions and 20 deletions

View File

@ -1,19 +0,0 @@
package photosapi
import (
"errors"
"net/http"
"github.com/gin-gonic/gin"
)
var (
ErrReqMissingBody = errors.New("missing body")
)
func (s *Service) RequireBody(c *gin.Context) {
if c.Request.Method == "POST" && c.Request.ContentLength == 0 {
c.AbortWithError(http.StatusBadRequest, ErrReqMissingBody)
return
}
}

View File

@ -0,0 +1,8 @@
package photosapi
import "github.com/gin-gonic/gin"
func (s *Service) DefaultJSON(c *gin.Context) {
c.Header("content-type", "application/json; charset=utf-8")
c.Next()
}

View File

@ -52,8 +52,8 @@ func (s *Service) SetupRoutes() {
s.Gin.Use( s.Gin.Use(
gin.Logger(), gin.Logger(),
s.Recovery, s.Recovery,
s.DefaultJSON,
s.HandleError, s.HandleError,
s.RequireBody,
) )
s.AccountInit() s.AccountInit()