diff --git a/cmd/ubsserver/main.go b/cmd/ubsserver/main.go index c2381ac..ffbf7b2 100644 --- a/cmd/ubsserver/main.go +++ b/cmd/ubsserver/main.go @@ -76,7 +76,18 @@ func info(w http.ResponseWriter, req *http.Request) { } } +func ensureJSONRequest(w http.ResponseWriter, req *http.Request) bool { + if strings.ToLower(req.Header["Content-Type"][0]) != "application/json" { + sendJSONError(w, syncstore.RequiredDataNotFoundError) + return false + } + return true +} + func createSync(w http.ResponseWriter, req *http.Request) { + if !ensureJSONRequest(w, req) { + return + } body := new(syncstore.CreateReq) req.Body = http.MaxBytesReader(w, req.Body, 10000) err := json.NewDecoder(req.Body).Decode(&body) @@ -124,6 +135,9 @@ func getVersion(syncId string, w http.ResponseWriter, _ *http.Request) { } func updateSync(syncId string, w http.ResponseWriter, req *http.Request) { + if !ensureJSONRequest(w, req) { + return + } body := new(syncstore.UpdateReq) req.Body = http.MaxBytesReader(w, req.Body, int64(10000 + maxSyncSize)) err := json.NewDecoder(req.Body).Decode(&body) diff --git a/syncstore/errors.go b/syncstore/errors.go index 7755a68..5b52ade 100644 --- a/syncstore/errors.go +++ b/syncstore/errors.go @@ -52,4 +52,9 @@ var ( "SyncDataLimitExceededException", "Sync data limit exceeded", http.StatusRequestEntityTooLarge) + + RequiredDataNotFoundError = NewSyncError( + "RequiredDataNotFoundException", + "Unable to find required data", + http.StatusBadRequest) )