refactor: incorporate Copilot review suggestions

This commit is contained in:
Raju Ahmed 2026-06-02 22:43:11 +06:00
parent 7b5727c6db
commit f9beb88451
2 changed files with 9 additions and 6 deletions

View File

@ -1158,8 +1158,11 @@ func (c *Context) Render(code int, r render.Render) {
return
}
if c.Writer.Written() && IsDebugging() {
// Skip warning for SSE and streaming responses (status code -1)
if c.Writer.Size() > 0 && IsDebugging() {
// Skip this warning when:
// - status code is -1, which is used for special/streaming-style renders (including some
// non-streaming helpers like redirects) where multiple writes are expected, and
// - the renderer is an SSE event, since Server-Sent Events are sent as a stream.
if code != -1 {
if _, ok := r.(sse.Event); !ok {
debugPrint("[WARNING] Response body already written. Attempting to write again with status code %d", code)

View File

@ -1429,8 +1429,8 @@ func TestContextRenderMultipleJSON(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
oldMode := os.Getenv("GIN_MODE")
defer os.Setenv("GIN_MODE", oldMode)
oldMode := Mode()
defer SetMode(oldMode)
SetMode(DebugMode)
output := captureOutput(t, func() {
@ -1448,8 +1448,8 @@ func TestContextRenderMultipleSSE(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
oldMode := os.Getenv("GIN_MODE")
defer os.Setenv("GIN_MODE", oldMode)
oldMode := Mode()
defer SetMode(oldMode)
SetMode(DebugMode)
output := captureOutput(t, func() {