File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 2121func PurgeHandler (ctx v1alpha1.Context ) func (c * fiber.Ctx ) error {
2222 return func (c * fiber.Ctx ) error {
2323
24+ // Verify the Content-Type header
25+ if c .Get ("Content-Type" ) != "application/json" {
26+ ctx .Logger .Error ("Invalid content type" )
27+ return c .Status (fiber .StatusBadRequest ).JSON (map [string ]string {
28+ "error" : "Invalid content type" ,
29+ })
30+ }
31+
32+ // Verify body to be really a JSON
33+ if ! json .Valid (c .Body ()) {
34+ ctx .Logger .Error ("Invalid JSON body" )
35+ return c .Status (fiber .StatusBadRequest ).JSON (map [string ]string {
36+ "error" : "Invalid JSON body" ,
37+ })
38+ }
39+
2440 // Parse the JSON body from the request and validate the body
2541 if err := c .BodyParser (& req ); err != nil {
2642 ctx .Logger .Errorf ("Failed to parse request: %v\n " , err )
You can’t perform that action at this time.
0 commit comments