inherit context from http.Request for ghttp.Request (#2550)

This commit is contained in:
John Guo
2023-04-12 11:54:06 +08:00
committed by GitHub
parent 5f148632d2
commit 7ff7de4643
2 changed files with 11 additions and 5 deletions

View File

@ -26,10 +26,7 @@ func RequestFromCtx(ctx context.Context) *Request {
// See GetCtx.
func (r *Request) Context() context.Context {
if r.context == nil {
// DO NOT use the http context as it will be canceled after request done,
// which makes the asynchronous goroutine encounter "context canceled" error.
// r.context = r.Request.Context()
r.context = gctx.New()
r.context = gctx.WithCtx(r.Request.Context())
}
// Inject Request object into context.
if RequestFromCtx(r.context) == nil {