Skip to content

Commit

Permalink
add content type before writing header (netbirdio#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcmmbaga authored Apr 25, 2024
1 parent 7b254cb commit 71c6437
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion management/server/http/setupkeys_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (h *SetupKeysHandler) GetAllSetupKeys(w http.ResponseWriter, r *http.Reques
}

func writeSuccess(w http.ResponseWriter, key *server.SetupKey) {
w.WriteHeader(200)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
err := json.NewEncoder(w).Encode(toResponseBody(key))
if err != nil {
util.WriteError(err, w)
Expand Down
4 changes: 2 additions & 2 deletions management/server/http/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type ErrorResponse struct {

// WriteJSONObject simply writes object to the HTTP response in JSON format
func WriteJSONObject(w http.ResponseWriter, obj interface{}) {
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
err := json.NewEncoder(w).Encode(obj)
if err != nil {
WriteError(err, w)
Expand Down Expand Up @@ -63,8 +63,8 @@ func (d *Duration) UnmarshalJSON(b []byte) error {

// WriteErrorResponse prepares and writes an error response i nJSON
func WriteErrorResponse(errMsg string, httpStatus int, w http.ResponseWriter) {
w.WriteHeader(httpStatus)
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(httpStatus)
err := json.NewEncoder(w).Encode(&ErrorResponse{
Message: errMsg,
Code: httpStatus,
Expand Down

0 comments on commit 71c6437

Please sign in to comment.