From 8c445610d091bb26f030211facc00c5557cbc355 Mon Sep 17 00:00:00 2001 From: Landon Cox Date: Thu, 9 Apr 2026 11:17:51 -0700 Subject: [PATCH] fix: use json.Marshal in WriteJSONResponse to avoid trailing newline json.Encoder.Encode appends a trailing newline character after the JSON output. This caused 8 proxy tests to fail after commit f9f875b refactored manual w.Write calls to use WriteJSONResponse. Switch from json.NewEncoder(w).Encode(body) to json.Marshal(body) + w.Write(data), which produces clean JSON without a trailing newline. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/httputil/httputil.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/httputil/httputil.go b/internal/httputil/httputil.go index b3390ba3..ba004e91 100644 --- a/internal/httputil/httputil.go +++ b/internal/httputil/httputil.go @@ -12,5 +12,9 @@ import ( func WriteJSONResponse(w http.ResponseWriter, statusCode int, body interface{}) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(statusCode) - json.NewEncoder(w).Encode(body) + data, err := json.Marshal(body) + if err != nil { + return + } + w.Write(data) }