SendErrorJSON sets Content-Type: text/plain instead Content-Type: application/json; charset=utf-8
egregors opened this issue · 1 comments
egregors commented
github.com/go-pkgz/rest v1.5.0
For some reason, SendErrorJSON
writes the wrong Content-Type.
rest.SendErrorJSON(w, r, nil, http.StatusNotFound, nil, "nothing to show")
Response:
HTTP/1.1 404 Not Found
Date: Thu, 07 May 2020 08:21:12 GMT
Content-Length: 28
Content-Type: text/plain; charset=utf-8
{"error":"nothing to show"}
Response code: 404 (Not Found); Time: 22ms; Content length: 28 bytes
Looks like w.Header().Set("Content-Type", "application/json; charset=utf-8")
should be called before w.WriteHeader(code)
.