Fix: Adjust header setting order in error response functions (#699)

This commit is contained in:
Ralph Slooten
2026-06-13 08:46:15 +12:00
parent 2db18f671f
commit fc83f4881a

View File

@@ -16,8 +16,8 @@ import (
func fourOFour(w http.ResponseWriter) {
w.Header().Set("Referrer-Policy", "no-referrer")
w.Header().Set("Content-Security-Policy", config.ContentSecurityPolicy)
w.WriteHeader(http.StatusNotFound)
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
_, _ = fmt.Fprint(w, "404 page not found")
}
@@ -25,8 +25,8 @@ func fourOFour(w http.ResponseWriter) {
func httpError(w http.ResponseWriter, msg string) {
w.Header().Set("Referrer-Policy", "no-referrer")
w.Header().Set("Content-Security-Policy", config.ContentSecurityPolicy)
w.WriteHeader(http.StatusBadRequest)
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusBadRequest)
_, _ = fmt.Fprint(w, msg)
}
@@ -34,10 +34,10 @@ func httpError(w http.ResponseWriter, msg string) {
func httpJSONError(w http.ResponseWriter, msg string) {
w.Header().Set("Referrer-Policy", "no-referrer")
w.Header().Set("Content-Security-Policy", config.ContentSecurityPolicy)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusBadRequest)
e := struct{ Error string }{Error: msg}
w.Header().Add("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(e); err != nil {
httpError(w, err.Error())
}