diff --git a/gorush/server.go b/gorush/server.go index e807ae6..eb68bf3 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "golang.org/x/crypto/acme/autocert" @@ -35,7 +36,7 @@ func pushHandler(c *gin.Context) { var form RequestPush var msg string - if err := c.BindJSON(&form); err != nil { + if err := c.ShouldBindWith(&form, binding.JSON); err != nil { msg = "Missing notifications field." LogAccess.Debug(msg) abortWithError(c, http.StatusBadRequest, msg) diff --git a/gorush/server_test.go b/gorush/server_test.go index 411aa4a..6515b3e 100644 --- a/gorush/server_test.go +++ b/gorush/server_test.go @@ -101,6 +101,7 @@ func TestRootHandler(t *testing.T) { assert.Equal(t, "Welcome to notification server.", value) assert.Equal(t, http.StatusOK, r.Code) + assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type")) }) } @@ -160,6 +161,7 @@ func TestMissingNotificationsParameter(t *testing.T) { Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) { assert.Equal(t, http.StatusBadRequest, r.Code) + assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type")) }) }