mirror of
https://github.com/gin-gonic/gin.git
synced 2026-07-11 21:31:16 +08:00
Merge 094ea8276ac42e1c9d541f6c2139747b8d0a49e4 into d75fcd4c9ab260e5225de590f1f0f8c0e0e12d11
This commit is contained in:
commit
b17fa886d0
11
context.go
11
context.go
@ -94,6 +94,11 @@ type Context struct {
|
|||||||
// SameSite allows a server to define a cookie attribute making it impossible for
|
// SameSite allows a server to define a cookie attribute making it impossible for
|
||||||
// the browser to send this cookie along with cross-site requests.
|
// the browser to send this cookie along with cross-site requests.
|
||||||
sameSite http.SameSite
|
sameSite http.SameSite
|
||||||
|
|
||||||
|
// wroteResponse tracks whether a response has been written to the client.
|
||||||
|
// This is used to warn about multiple response writes, which can lead to
|
||||||
|
// unexpected behavior.
|
||||||
|
wroteResponse bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
@ -113,6 +118,7 @@ func (c *Context) reset() {
|
|||||||
c.queryCache = nil
|
c.queryCache = nil
|
||||||
c.formCache = nil
|
c.formCache = nil
|
||||||
c.sameSite = 0
|
c.sameSite = 0
|
||||||
|
c.wroteResponse = false
|
||||||
*c.params = (*c.params)[:0]
|
*c.params = (*c.params)[:0]
|
||||||
*c.skippedNodes = (*c.skippedNodes)[:0]
|
*c.skippedNodes = (*c.skippedNodes)[:0]
|
||||||
}
|
}
|
||||||
@ -1177,11 +1183,15 @@ func (c *Context) Cookie(name string) (string, error) {
|
|||||||
|
|
||||||
// Render writes the response headers and calls render.Render to render data.
|
// Render writes the response headers and calls render.Render to render data.
|
||||||
func (c *Context) Render(code int, r render.Render) {
|
func (c *Context) Render(code int, r render.Render) {
|
||||||
|
if c.wroteResponse {
|
||||||
|
debugPrint("[WARNING] Multiple response writes detected. This may cause unexpected behavior.")
|
||||||
|
}
|
||||||
c.Status(code)
|
c.Status(code)
|
||||||
|
|
||||||
if !bodyAllowedForStatus(code) {
|
if !bodyAllowedForStatus(code) {
|
||||||
r.WriteContentType(c.Writer)
|
r.WriteContentType(c.Writer)
|
||||||
c.Writer.WriteHeaderNow()
|
c.Writer.WriteHeaderNow()
|
||||||
|
c.wroteResponse = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,6 +1200,7 @@ func (c *Context) Render(code int, r render.Render) {
|
|||||||
_ = c.Error(err)
|
_ = c.Error(err)
|
||||||
c.Abort()
|
c.Abort()
|
||||||
}
|
}
|
||||||
|
c.wroteResponse = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML renders the HTTP template specified by its file name.
|
// HTML renders the HTTP template specified by its file name.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user