mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
29
conn.go
29
conn.go
@@ -50,37 +50,16 @@ func taskMain(conn http1.Conn, task *reqTask) (err error) {
|
||||
return
|
||||
default:
|
||||
}
|
||||
done := make(chan struct{})
|
||||
var derr error
|
||||
var response *http.Response
|
||||
go func() {
|
||||
defer close(done)
|
||||
response, derr = conn.DoRequest(task.reqCtx.request, &http1.Option{OrderHeaders: task.reqCtx.option.orderHeaders.Data()})
|
||||
}()
|
||||
if task.reqCtx.option.ResponseHeaderTimeout > 0 {
|
||||
select {
|
||||
case <-conn.Context().Done(): //force conn close
|
||||
err = tools.WrapError(context.Cause(conn.Context()), "taskMain delete ctx error")
|
||||
case <-time.After(task.reqCtx.option.ResponseHeaderTimeout):
|
||||
err = errors.New("ResponseHeaderTimeout error: ")
|
||||
case <-task.ctx.Done():
|
||||
err = context.Cause(task.ctx)
|
||||
case <-done:
|
||||
}
|
||||
ctx, cnl := context.WithTimeout(task.reqCtx.Context(), task.reqCtx.option.ResponseHeaderTimeout)
|
||||
response, err = conn.DoRequest(ctx, task.reqCtx.request, &http1.Option{OrderHeaders: task.reqCtx.option.orderHeaders.Data()})
|
||||
cnl()
|
||||
} else {
|
||||
select {
|
||||
case <-conn.Context().Done(): //force conn close
|
||||
err = tools.WrapError(context.Cause(conn.Context()), "taskMain delete ctx error")
|
||||
case <-task.ctx.Done():
|
||||
err = context.Cause(task.ctx)
|
||||
case <-done:
|
||||
}
|
||||
response, err = conn.DoRequest(task.reqCtx.Context(), task.reqCtx.request, &http1.Option{OrderHeaders: task.reqCtx.option.orderHeaders.Data()})
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
err = tools.WrapError(err, "roundTrip error")
|
||||
} else if derr != nil {
|
||||
err = tools.WrapError(derr, "roundTrip error")
|
||||
} else {
|
||||
task.reqCtx.response = response
|
||||
task.reqCtx.response.Request = task.reqCtx.request
|
||||
|
||||
4
go.mod
4
go.mod
@@ -14,8 +14,8 @@ require (
|
||||
github.com/gospider007/http3 v0.0.0-20250729013804-e1c3cbcf998f
|
||||
github.com/gospider007/ja3 v0.0.0-20250724085013-aa7e0a527d6c
|
||||
github.com/gospider007/re v0.0.0-20250217075352-bcb79f285d6c
|
||||
github.com/gospider007/tools v0.0.0-20250718003809-7c62cd0ee920
|
||||
github.com/gospider007/websocket v0.0.0-20250718010025-4c017acfd478
|
||||
github.com/gospider007/tools v0.0.0-20250730001814-2c13a4717064
|
||||
github.com/gospider007/websocket v0.0.0-20250730001828-b2c8c6bef799
|
||||
github.com/klauspost/compress v1.18.0
|
||||
github.com/minio/minlz v1.0.1
|
||||
github.com/quic-go/quic-go v0.54.0
|
||||
|
||||
8
go.sum
8
go.sum
@@ -126,10 +126,10 @@ github.com/gospider007/kinds v0.0.0-20250217075226-10f199f7215d h1:+Fih572EdNmYC
|
||||
github.com/gospider007/kinds v0.0.0-20250217075226-10f199f7215d/go.mod h1:3u6J+nbdWhCNJGiQjq/hKSukn2k6ebjd98rd2+fzKNo=
|
||||
github.com/gospider007/re v0.0.0-20250217075352-bcb79f285d6c h1:8/Cf+c2680tkWJ+ueZ9RLLK5R5R8nhE8pNBUPHjkvkM=
|
||||
github.com/gospider007/re v0.0.0-20250217075352-bcb79f285d6c/go.mod h1:dd8aDIUG1vDPP5r+vHBtiUK0Zn6uk3SsWt1ZvmCCHLs=
|
||||
github.com/gospider007/tools v0.0.0-20250718003809-7c62cd0ee920 h1:WZof+Xg/syAFRGHTPa9Cct6OLrtx8wHcAgGOC6ggFT4=
|
||||
github.com/gospider007/tools v0.0.0-20250718003809-7c62cd0ee920/go.mod h1:i0V5k/zJW/ghTLLWY40pwTVuwa/Gxm2Q1IP1vQYHBX8=
|
||||
github.com/gospider007/websocket v0.0.0-20250718010025-4c017acfd478 h1:tVIWVD9oHdmIIA506SQ7qbx4vTlckxzk/JKhuDCzkHw=
|
||||
github.com/gospider007/websocket v0.0.0-20250718010025-4c017acfd478/go.mod h1:okAxHf/CcV7d+iCl9dYRpe1rIyaOcR/DxIDj2KAzFDk=
|
||||
github.com/gospider007/tools v0.0.0-20250730001814-2c13a4717064 h1:zmdLFUzG87xgpDp6JnTr73t1f+LtOLufiL7dPT2nPVQ=
|
||||
github.com/gospider007/tools v0.0.0-20250730001814-2c13a4717064/go.mod h1:i0V5k/zJW/ghTLLWY40pwTVuwa/Gxm2Q1IP1vQYHBX8=
|
||||
github.com/gospider007/websocket v0.0.0-20250730001828-b2c8c6bef799 h1:xOjIXygt5inFogiC0BVHFQlUZ3j8d5q7jHy3C4Isv2w=
|
||||
github.com/gospider007/websocket v0.0.0-20250730001828-b2c8c6bef799/go.mod h1:mzusKGPxNYnxJBWJZp/uME5LmlIk3VROPMg7Q+v81mI=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
|
||||
Reference in New Issue
Block a user