Pull request 1839: 5716-write-json
Updates #5716. Squashed commit of the following: commit 8cf7c4f404fffb646c9df8643924eb8dc1d8f49d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Apr 19 18:09:35 2023 +0300 aghhttp: write json properly
This commit is contained in:
parent
d6043e2352
commit
757ddb06f8
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue