mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
fix #1856
This commit is contained in:
@@ -46,6 +46,12 @@ type Application interface {
|
||||
// Returns an error on failure, otherwise nil.
|
||||
View(writer io.Writer, filename string, layout string, bindingData interface{}) error
|
||||
|
||||
// GetContextPool returns the Iris sync.Pool which holds the contexts values.
|
||||
// Iris automatically releases the request context, so you don't have to use it.
|
||||
// It's only useful to manually release the context on cases that connection
|
||||
// is hijacked by a third-party middleware and the http handler return too fast.
|
||||
GetContextPool() *Pool
|
||||
|
||||
// ServeHTTPC is the internal router, it's visible because it can be used for advanced use cases,
|
||||
// i.e: routing within a foreign context.
|
||||
//
|
||||
|
||||
@@ -147,6 +147,9 @@ type Context struct {
|
||||
// Also it's responsible to keep the old value of the last known handler index
|
||||
// before StopExecution. See ResumeExecution.
|
||||
proceeded int
|
||||
|
||||
// if true, caller is responsible to release the context (put the context to the pool).
|
||||
manualRelease bool
|
||||
}
|
||||
|
||||
// NewContext returns a new Context instance.
|
||||
@@ -190,6 +193,7 @@ func (ctx *Context) Clone() *Context {
|
||||
request: req,
|
||||
currentHandlerIndex: stopExecutionIndex,
|
||||
proceeded: ctx.proceeded,
|
||||
manualRelease: ctx.manualRelease,
|
||||
currentRoute: ctx.currentRoute,
|
||||
}
|
||||
}
|
||||
@@ -213,6 +217,7 @@ func (ctx *Context) BeginRequest(w http.ResponseWriter, r *http.Request) {
|
||||
ctx.request = r
|
||||
ctx.currentHandlerIndex = 0
|
||||
ctx.proceeded = 0
|
||||
ctx.manualRelease = false
|
||||
ctx.writer = AcquireResponseWriter()
|
||||
ctx.writer.BeginResponse(w)
|
||||
}
|
||||
@@ -233,6 +238,12 @@ func (ctx *Context) EndRequest() {
|
||||
ctx.writer.EndResponse()
|
||||
}
|
||||
|
||||
// DisablePoolRelease disables the auto context pool Put call.
|
||||
// Do NOT use it, unless you know what you are doing.
|
||||
func (ctx *Context) DisablePoolRelease() {
|
||||
ctx.manualRelease = true
|
||||
}
|
||||
|
||||
// IsCanceled reports whether the client canceled the request
|
||||
// or the underlying connection has gone.
|
||||
// Note that it will always return true
|
||||
|
||||
@@ -26,13 +26,17 @@ func (c *Pool) Acquire(w http.ResponseWriter, r *http.Request) *Context {
|
||||
// Release puts a Context back to its pull, this function releases its resources.
|
||||
// See Acquire.
|
||||
func (c *Pool) Release(ctx *Context) {
|
||||
ctx.EndRequest()
|
||||
c.pool.Put(ctx)
|
||||
if !ctx.manualRelease {
|
||||
ctx.EndRequest()
|
||||
c.pool.Put(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// ReleaseLight will just release the object back to the pool, but the
|
||||
// clean method is caller's responsibility now, currently this is only used
|
||||
// on `SPABuilder`.
|
||||
// on `SPABuilder` and `websocket.Handler`.
|
||||
//
|
||||
// ReleaseLight does a force-put, it does NOT respect the context.DisablePoolRelease.
|
||||
func (c *Pool) ReleaseLight(ctx *Context) {
|
||||
c.pool.Put(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user