Skip to content

Commit

Permalink
jhttp: set headers before calling WriteHeader
Browse files Browse the repository at this point in the history
This was actually safe as written, but the API does not
promise to honour headers set after the code is marked.
  • Loading branch information
creachadair committed Jan 15, 2022
1 parent 235ea4d commit 5ac8637
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion jhttp/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func writeJSON(w http.ResponseWriter, code int, obj interface{}) {
fmt.Fprintln(w, err.Error())
return
}
w.WriteHeader(code)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(bits)))
w.WriteHeader(code)
w.Write(bits)
}

0 comments on commit 5ac8637

Please sign in to comment.