mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-06 12:08:20 +08:00
refactor: incorporate Copilot review suggestions
This commit is contained in:
parent
7b5727c6db
commit
f9beb88451
@ -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)
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user