Skip to content

Commit

Permalink
server/writer: use Header().Set() not Header().Add() to avoid duplica…
Browse files Browse the repository at this point in the history
…te content-type headers

Signed-off-by: Stephan Renatus <[email protected]>
  • Loading branch information
srenatus committed Oct 15, 2024
1 parent cb3ac5a commit 34b80b3
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions server/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func ErrorString(w http.ResponseWriter, status int, code string, err error) {

// Error writes a response with specified status and error response.
func Error(w http.ResponseWriter, status int, err *types.ErrorV1) {
headers := w.Header()
headers.Add("Content-Type", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_, _ = w.Write(append(err.Bytes(), byte('\n')))
}
Expand All @@ -66,7 +65,7 @@ func JSON(w http.ResponseWriter, code int, v interface{}, pretty bool) {
enc.SetIndent("", " ")
}

w.Header().Add("Content-Type", "application/json")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)

if err := enc.Encode(v); err != nil {
Expand Down

0 comments on commit 34b80b3

Please sign in to comment.