mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-10 16:47:05 +08:00
Compare commits
2 Commits
e28944aae4
...
a09c5d162b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a09c5d162b | ||
|
|
5a59ab2450 |
@ -95,8 +95,9 @@ type Context struct {
|
|||||||
// 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
|
||||||
|
|
||||||
internalContextMu sync.RWMutex
|
internalContextMu sync.RWMutex
|
||||||
internalContext context.Context
|
internalContext context.Context
|
||||||
|
internalContextCancelCause context.CancelCauseFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************/
|
/************************************/
|
||||||
@ -1424,7 +1425,7 @@ func (c *Context) WithInternalContext(ctx context.Context) {
|
|||||||
c.internalContextMu.Lock()
|
c.internalContextMu.Lock()
|
||||||
defer c.internalContextMu.Unlock()
|
defer c.internalContextMu.Unlock()
|
||||||
|
|
||||||
c.internalContext = ctx
|
c.internalContext, c.internalContextCancelCause = context.WithCancelCause(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalContext provides the currently stored internal context in a thread safe manner.
|
// InternalContext provides the currently stored internal context in a thread safe manner.
|
||||||
|
|||||||
14
gin.go
14
gin.go
@ -674,6 +674,20 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
c.Request = req
|
c.Request = req
|
||||||
c.reset()
|
c.reset()
|
||||||
|
|
||||||
|
// If we're using internalContext then we need to pass on errors from the request context
|
||||||
|
if c.useInternalContext() {
|
||||||
|
reqCtx := req.Context()
|
||||||
|
go func() {
|
||||||
|
<-reqCtx.Done()
|
||||||
|
if err := reqCtx.Err(); err != nil {
|
||||||
|
c.internalContextMu.RLock()
|
||||||
|
defer c.internalContextMu.RUnlock()
|
||||||
|
|
||||||
|
c.internalContextCancelCause(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
engine.handleHTTPRequest(c)
|
engine.handleHTTPRequest(c)
|
||||||
|
|
||||||
engine.pool.Put(c)
|
engine.pool.Put(c)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user