add wildcard checks to checkHeaderAcceptJSON()

This commit is contained in:
Travis Turner 2018-06-24 22:45:35 -05:00
parent c1f11d40e4
commit 9d3332929d
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -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.