diff options
Diffstat (limited to 'cmd/blubberoid/main.go')
-rw-r--r-- | cmd/blubberoid/main.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/blubberoid/main.go b/cmd/blubberoid/main.go index 73b10a6..d436390 100644 --- a/cmd/blubberoid/main.go +++ b/cmd/blubberoid/main.go @@ -3,9 +3,11 @@ package main import ( + "encoding/json" "fmt" "io/ioutil" "log" + "mime" "net/http" "os" "path" @@ -71,6 +73,23 @@ func blubberoid(res http.ResponseWriter, req *http.Request) { return } + switch mt, _, _ := mime.ParseMediaType(req.Header.Get("content-type")); mt { + case "application/json": + // Enforce strict JSON syntax if specified, even though the config parser + // would technically handle anything that's at least valid YAML + if !json.Valid(body) { + res.WriteHeader(http.StatusBadRequest) + res.Write(responseBody("'%s' media type given but request contains invalid JSON", mt)) + return + } + case "application/yaml", "application/x-yaml": + // Let the config parser validate YAML syntax + default: + res.WriteHeader(http.StatusUnsupportedMediaType) + res.Write(responseBody("'%s' media type is not supported", mt)) + return + } + cfg, err := config.ReadYAMLConfig(body) if err != nil { |