mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-04 14:49:27 +08:00
Merge a2a45467de7d98f73f676a3eeba4b7c4a5b50bdf into dcaa4296d111981ffb31ac3eba90bb63e1eb5ab9
This commit is contained in:
commit
c184b1e67c
@ -1208,6 +1208,10 @@ func (c *Context) Render(code int, r render.Render) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Writer.Written() {
|
||||||
|
debugPrint("[WARNING] Response body has already been written. Wanted to override response.")
|
||||||
|
}
|
||||||
|
|
||||||
if err := r.Render(c.Writer); err != nil {
|
if err := r.Render(c.Writer); err != nil {
|
||||||
// Pushing error to c.Errors
|
// Pushing error to c.Errors
|
||||||
_ = c.Error(err)
|
_ = c.Error(err)
|
||||||
|
|||||||
@ -251,3 +251,16 @@ func TestMiddlewareWrite(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||||
assert.Equal(t, strings.ReplaceAll("hola\n<map><foo>bar</foo></map>{\"foo\":\"bar\"}{\"foo\":\"bar\"}event:test\ndata:message\n\n", " ", ""), strings.ReplaceAll(w.Body.String(), " ", ""))
|
assert.Equal(t, strings.ReplaceAll("hola\n<map><foo>bar</foo></map>{\"foo\":\"bar\"}{\"foo\":\"bar\"}event:test\ndata:message\n\n", " ", ""), strings.ReplaceAll(w.Body.String(), " ", ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMultipleResponseWritesWarning(t *testing.T) {
|
||||||
|
router := New()
|
||||||
|
router.GET("/", func(c *Context) {
|
||||||
|
c.String(http.StatusOK, "first\n")
|
||||||
|
c.String(http.StatusOK, "second\n")
|
||||||
|
})
|
||||||
|
|
||||||
|
w := PerformRequest(router, http.MethodGet, "/")
|
||||||
|
|
||||||
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
|
assert.Equal(t, "first\nsecond\n", w.Body.String())
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user