Skip to content

Commit

Permalink
feat: add method to exile requestContext (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
welkeyever authored May 9, 2024
1 parent b5b3f9d commit 2d13882
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ type RequestContext struct {

binder binding.Binder
validator binding.StructValidator
exiled bool
}

// Exile marks this RequestContext as not to be recycled.
// Experimental features: Use with caution, it may have a slight impact on performance.
func (ctx *RequestContext) Exile() {
ctx.exiled = true
}

func (ctx *RequestContext) IsExiled() bool {
return ctx.exiled
}

// Flush is the shortcut for ctx.Response.GetHijackWriter().Flush().
Expand Down
5 changes: 5 additions & 0 deletions pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) {
zr.Release() //nolint:errcheck
zr = nil
}

if ctx.IsExiled() {
return
}

ctx.Reset()
s.Core.GetCtxPool().Put(ctx)
}()
Expand Down

0 comments on commit 2d13882

Please sign in to comment.