mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-12 17:46:57 +08:00
fix(context): added warning for multiple writes to response body
warning works only in debug mode
This commit is contained in:
parent
26c3a62865
commit
8eb015d2bc
@ -1132,6 +1132,15 @@ 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 code != -1 {
|
||||
if _, ok := r.(sse.Event); !ok {
|
||||
debugPrint("[WARNING] Response body already written. Attempting to write again with status code %d", code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := r.Render(c.Writer); err != nil {
|
||||
// Pushing error to c.Errors
|
||||
_ = c.Error(err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user