mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
45
http.go
45
http.go
@@ -128,6 +128,21 @@ func (obj *clientConn) CloseWithError(err error) error {
|
|||||||
}
|
}
|
||||||
return obj.conn.Close()
|
return obj.conn.Close()
|
||||||
}
|
}
|
||||||
|
func (obj *clientConn) initTask(req *http.Request, orderHeaders []interface {
|
||||||
|
Key() string
|
||||||
|
Val() any
|
||||||
|
}) {
|
||||||
|
readCtx, readCnl := context.WithCancelCause(obj.closeCtx)
|
||||||
|
writeCtx, writeCnl := context.WithCancel(obj.closeCtx)
|
||||||
|
obj.task = &httpTask{
|
||||||
|
readCtx: readCtx,
|
||||||
|
readCnl: readCnl,
|
||||||
|
writeCtx: writeCtx,
|
||||||
|
writeCnl: writeCnl,
|
||||||
|
req: req,
|
||||||
|
orderHeaders: orderHeaders,
|
||||||
|
}
|
||||||
|
}
|
||||||
func (obj *clientConn) DoRequest(req *http.Request, orderHeaders []interface {
|
func (obj *clientConn) DoRequest(req *http.Request, orderHeaders []interface {
|
||||||
Key() string
|
Key() string
|
||||||
Val() any
|
Val() any
|
||||||
@@ -142,27 +157,33 @@ func (obj *clientConn) DoRequest(req *http.Request, orderHeaders []interface {
|
|||||||
if obj.task != nil {
|
if obj.task != nil {
|
||||||
select {
|
select {
|
||||||
case <-obj.task.writeCtx.Done():
|
case <-obj.task.writeCtx.Done():
|
||||||
|
case <-obj.ctx.Done():
|
||||||
|
return nil, nil, obj.ctx.Err()
|
||||||
|
case <-obj.closeCtx.Done():
|
||||||
|
return nil, nil, obj.closeCtx.Err()
|
||||||
default:
|
default:
|
||||||
return nil, obj.task.readCtx, errLastTaskRuning
|
return nil, obj.task.readCtx, errLastTaskRuning
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case <-obj.task.readCtx.Done():
|
case <-obj.task.readCtx.Done():
|
||||||
|
case <-obj.ctx.Done():
|
||||||
|
return nil, nil, obj.ctx.Err()
|
||||||
|
case <-obj.closeCtx.Done():
|
||||||
|
return nil, nil, obj.closeCtx.Err()
|
||||||
|
default:
|
||||||
|
return nil, obj.task.readCtx, errLastTaskRuning
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
select {
|
||||||
|
case <-obj.ctx.Done():
|
||||||
|
return nil, nil, obj.ctx.Err()
|
||||||
|
case <-obj.closeCtx.Done():
|
||||||
|
return nil, nil, obj.closeCtx.Err()
|
||||||
default:
|
default:
|
||||||
return nil, obj.task.readCtx, errLastTaskRuning
|
return nil, obj.task.readCtx, errLastTaskRuning
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
readCtx, readCnl := context.WithCancelCause(obj.closeCtx)
|
obj.initTask(req, orderHeaders)
|
||||||
writeCtx, writeCnl := context.WithCancel(obj.closeCtx)
|
|
||||||
obj.task = &httpTask{
|
|
||||||
readCtx: readCtx,
|
|
||||||
readCnl: readCnl,
|
|
||||||
|
|
||||||
writeCtx: writeCtx,
|
|
||||||
writeCnl: writeCnl,
|
|
||||||
|
|
||||||
req: req,
|
|
||||||
orderHeaders: orderHeaders,
|
|
||||||
}
|
|
||||||
obj.send()
|
obj.send()
|
||||||
if obj.task.err != nil {
|
if obj.task.err != nil {
|
||||||
obj.CloseWithError(obj.task.err)
|
obj.CloseWithError(obj.task.err)
|
||||||
|
|||||||
Reference in New Issue
Block a user