Commit 81fdf1e
authored
fix: use json.Marshal in WriteJSONResponse to avoid trailing newline (#3466)
## Problem
Commit f9f875b refactored two sites in `internal/proxy/handler.go` to
use `httputil.WriteJSONResponse` instead of manual `w.Write` calls.
However, `WriteJSONResponse` used `json.NewEncoder(w).Encode(body)`,
which [always appends a trailing
newline](https://pkg.go.dev/encoding/json#Encoder.Encode). This caused 8
proxy tests to fail:
- `TestWriteEmptyResponse` (6 subtests)
- `TestHandleWithDIFC_LabelResponseError_CoarseBlocked`
- `TestHandleWithDIFC_NoFineGrainedLabels_CoarseBlocked`
All failures showed the same pattern: expected `"[]"` but got `"[]\n"`.
## Fix
Switch `WriteJSONResponse` from `json.NewEncoder(w).Encode(body)` to
`json.Marshal(body)` + `w.Write(data)`, which produces clean JSON
without a trailing newline. This is the standard approach for HTTP JSON
responses.
## Verification
`make agent-finished` passes — all unit and integration tests green.1 file changed
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
0 commit comments