From 9d3332929df848140e40de874985c2da3c280e6c Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Sun, 24 Jun 2018 22:45:35 -0500 Subject: [PATCH] add wildcard checks to checkHeaderAcceptJSON() --- http/handler.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/http/handler.go b/http/handler.go index 674381905..787cf3b9c 100644 --- a/http/handler.go +++ b/http/handler.go @@ -258,19 +258,19 @@ func (h *Handler) handleHome(w http.ResponseWriter, r *http.Request) { http.Error(w, "Welcome. Pilosa is running. Visit https://www.pilosa.com/docs/ for more information.", http.StatusNotFound) } +// checkHeaderAcceptJSON returns true if one or more Accept +// headers are present, but none of them are "application/json" +// (or any matching wildcard). Otherwise returns false. func checkHeaderAcceptJSON(header http.Header) bool { - v, found := header["Accept"] - sendError := false - if found { - sendError = true + if v, found := header["Accept"]; found { for _, v := range v { - if v == "application/json" { - sendError = false - + if v == "application/json" || v == "*/*" || v == "*/json" || v == "application/*" { + return false } } + return true } - return sendError + return false } // handleGetSchema handles GET /schema requests.