mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-22 20:49:23 +08:00
add method for handling contexts without resetting
HandleContext resets contexts completely, overwriting any modifications since GetContext was called. This is undermines the purpose of being able to GetContexts separately, so this commit adds a new method which only resets the index, but leaves everything else intact.
This commit is contained in:
parent
9c6f92b16b
commit
c17ae54e64
10
gin.go
10
gin.go
@ -588,6 +588,16 @@ func (engine *Engine) ReleaseContext(c *Context) {
|
|||||||
engine.pool.Put(c)
|
engine.pool.Put(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleContextAsIs handles the context as is without resetting it. This means
|
||||||
|
// that all key/values, middleware, etc. will be retained. This is useful for
|
||||||
|
// handling a context that has been created with *Engine.GetContext.
|
||||||
|
func (engine *Engine) HandleContextAsIs(c *Context) {
|
||||||
|
oldIndex := c.index
|
||||||
|
c.index = -1
|
||||||
|
engine.handleHTTPRequest(c)
|
||||||
|
c.index = oldIndex
|
||||||
|
}
|
||||||
|
|
||||||
// ServeHTTP conforms to the http.Handler interface.
|
// ServeHTTP conforms to the http.Handler interface.
|
||||||
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
c := engine.GetContext(w, req)
|
c := engine.GetContext(w, req)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user