Skip to content

Commit f9f875b

Browse files
refactor(proxy): use httputil.WriteJSONResponse for filtered/empty JSON writes
Two sites in handler.go manually set Content-Type, called WriteHeader, and wrote raw bytes instead of using the project's httputil.WriteJSONResponse helper that is already used elsewhere in the same file. - handleWithDIFC: replace 3-line manual block with WriteJSONResponse + json.RawMessage(filteredJSON) to preserve pre-serialized bytes as-is - writeEmptyResponse: restructure to determine empty string before calling WriteJSONResponse + json.RawMessage(empty) Closes #3312 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 46495a3 commit f9f875b

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

internal/proxy/handler.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,7 @@ func (h *proxyHandler) handleWithDIFC(w http.ResponseWriter, r *http.Request, pa
327327
return
328328
}
329329
copyResponseHeaders(w, resp)
330-
w.Header().Set("Content-Type", "application/json")
331-
w.WriteHeader(resp.StatusCode)
332-
w.Write(filteredJSON)
330+
httputil.WriteJSONResponse(w, resp.StatusCode, json.RawMessage(filteredJSON))
333331
}
334332
}
335333

@@ -364,8 +362,6 @@ func (h *proxyHandler) writeResponse(w http.ResponseWriter, resp *http.Response,
364362
// and for other JSON objects it writes "{}".
365363
func (h *proxyHandler) writeEmptyResponse(w http.ResponseWriter, resp *http.Response, originalData interface{}) {
366364
copyResponseHeaders(w, resp)
367-
w.Header().Set("Content-Type", "application/json")
368-
w.WriteHeader(resp.StatusCode)
369365

370366
var empty string
371367
switch obj := originalData.(type) {
@@ -381,7 +377,7 @@ func (h *proxyHandler) writeEmptyResponse(w http.ResponseWriter, resp *http.Resp
381377
default:
382378
empty = "[]" // safe default for nil or unknown types
383379
}
384-
w.Write([]byte(empty))
380+
httputil.WriteJSONResponse(w, resp.StatusCode, json.RawMessage(empty))
385381
}
386382

387383
// forwardAndReadBody forwards a request to the upstream GitHub API and reads the

0 commit comments

Comments
 (0)