This commit is contained in:
gospider
2025-08-15 11:14:01 +08:00
parent f7f37f2c2f
commit 69ad730363
2 changed files with 5 additions and 9 deletions

12
conn.go
View File

@@ -23,20 +23,16 @@ func taskMain(conn http1.Conn, task *reqTask) (err error) {
if err != nil { if err != nil {
task.cnl(err) task.cnl(err)
} else { } else {
var bodyCtx context.Context
if task.reqCtx.response != nil && task.reqCtx.response.Body != nil {
bodyCtx = task.reqCtx.response.Body.(*http1.Body).Context()
}
task.cnl(tools.ErrNoErr) task.cnl(tools.ErrNoErr)
if bodyCtx != nil { if bodyContext := conn.BodyContext(); bodyContext != nil {
select { select {
case <-task.reqCtx.Context().Done(): case <-task.reqCtx.Context().Done():
if context.Cause(task.reqCtx.Context()) != tools.ErrNoErr { if context.Cause(task.reqCtx.Context()) != tools.ErrNoErr {
err = context.Cause(task.reqCtx.Context()) err = context.Cause(task.reqCtx.Context())
} }
case <-bodyCtx.Done(): case <-bodyContext.Done():
if context.Cause(bodyCtx) != tools.ErrNoErr { if context.Cause(bodyContext) != tools.ErrNoErr {
err = context.Cause(bodyCtx) err = context.Cause(bodyContext)
} }
} }
} }

2
go.mod
View File

@@ -1,6 +1,6 @@
module github.com/gospider007/requests module github.com/gospider007/requests
go 1.24.0 go 1.25
require ( require (
github.com/golang/snappy v1.0.0 github.com/golang/snappy v1.0.0