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

@ -66,7 +66,9 @@ jobs:
- 3306:3306
# PostgreSQL backend server.
# docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=12345678 -e POSTGRES_USER=postgres -e POSTGRES_DB=test -v postgres:/Users/john/Temp/postgresql/data loads/postgres:13
# docker run -d --name postgres -p 5432:5432 \
# -e POSTGRES_PASSWORD=12345678 -e POSTGRES_USER=postgres -e POSTGRES_DB=test \
# -v postgres:/Users/john/Temp/postgresql/data loads/postgres:13
postgres:
image: loads/postgres:13
env:
@ -84,6 +86,13 @@ jobs:
--health-retries 5
# MSSQL backend server.
# docker run -d --name mssql -p 1433:1433 \
# -e ACCEPT_EULA=Y \
# -e SA_PASSWORD=LoremIpsum86 \
# -e MSSQL_DB=test \
# -e MSSQL_USER=root \
# -e MSSQL_PASSWORD=LoremIpsum86 \
# loads/mssqldocker:14.0.3391.2
mssql:
image: loads/mssqldocker:14.0.3391.2
env:

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 {