Relax content-type checking. Log errors.

This commit is contained in:
Maurizio Porrato 2021-05-22 14:55:08 +01:00
parent 9c92ba5c7f
commit f18da80e0d
Signed by: guru
GPG Key ID: C622977DF024AC24
1 changed files with 3 additions and 1 deletions

View File

@ -63,6 +63,7 @@ func sendJSONOk(w http.ResponseWriter, data interface{}) {
}
func sendJSONError(w http.ResponseWriter, err error) {
log.Println("ERROR: ", err)
switch e := err.(type) {
case bsync.SyncError:
sendJSON(w, e.StatusCode, e.Payload)
@ -89,7 +90,8 @@ 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" {
contentType := strings.Split(strings.ToLower(req.Header["Content-Type"][0]), ";")[0]
if contentType != "application/json" {
sendJSONError(w, bsync.RequiredDataNotFoundError)
return false
}