From 757ddb06f8973b8c550f309ca8771a53b68aaa87 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Wed, 19 Apr 2023 18:15:17 +0300 Subject: [PATCH] Pull request 1839: 5716-write-json Updates #5716. Squashed commit of the following: commit 8cf7c4f404fffb646c9df8643924eb8dc1d8f49d Author: Ainar Garipov Date: Wed Apr 19 18:09:35 2023 +0300 aghhttp: write json properly --- internal/aghhttp/aghhttp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/aghhttp/aghhttp.go b/internal/aghhttp/aghhttp.go index b5878f92..6cb2c670 100644 --- a/internal/aghhttp/aghhttp.go +++ b/internal/aghhttp/aghhttp.go @@ -72,8 +72,8 @@ func WriteJSONResponse(w http.ResponseWriter, r *http.Request, resp any) (err er // WriteJSONResponseCode is like [WriteJSONResponse] but adds the ability to // redefine the status code. func WriteJSONResponseCode(w http.ResponseWriter, r *http.Request, code int, resp any) (err error) { - w.WriteHeader(code) w.Header().Set(httphdr.ContentType, HdrValApplicationJSON) + w.WriteHeader(code) err = json.NewEncoder(w).Encode(resp) if err != nil { Error(r, w, http.StatusInternalServerError, "encoding resp: %s", err)