mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
8
conn.go
8
conn.go
@@ -182,6 +182,14 @@ func (obj *connecotr) taskMain(task *reqTask) (retry bool) {
|
||||
case <-obj.forceCtx.Done(): //force conn close
|
||||
task.err = tools.WrapError(context.Cause(obj.forceCtx), "connecotr force close")
|
||||
}
|
||||
if task.reqCtx.option.Logger != nil {
|
||||
task.reqCtx.option.Logger(Log{
|
||||
Id: task.reqCtx.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ResponseBody,
|
||||
Msg: "response body",
|
||||
})
|
||||
}
|
||||
}
|
||||
if task.err != nil {
|
||||
obj.CloseWithError(task.err)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
|
||||
@@ -355,14 +354,6 @@ func (obj *Response) ReadBody() (err error) {
|
||||
err = obj.ctx.Err()
|
||||
case <-done:
|
||||
}
|
||||
if obj.option.Logger != nil {
|
||||
obj.option.Logger(Log{
|
||||
Id: obj.requestId,
|
||||
Time: time.Now(),
|
||||
Type: LogType_ResponseBody,
|
||||
Msg: "response body",
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
obj.ForceCloseConn()
|
||||
return errors.New("response read content error: " + err.Error())
|
||||
|
||||
11
rw.go
11
rw.go
@@ -7,18 +7,24 @@ import (
|
||||
)
|
||||
|
||||
type readWriteCloser struct {
|
||||
body io.ReadCloser
|
||||
conn *connecotr
|
||||
body io.ReadCloser
|
||||
conn *connecotr
|
||||
isClosed bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (obj *readWriteCloser) Conn() net.Conn {
|
||||
return obj.conn.Conn.(net.Conn)
|
||||
}
|
||||
func (obj *readWriteCloser) Read(p []byte) (n int, err error) {
|
||||
if obj.isClosed {
|
||||
return 0, obj.err
|
||||
}
|
||||
i, err := obj.body.Read(p)
|
||||
if err == io.EOF {
|
||||
obj.Close()
|
||||
}
|
||||
obj.err = err
|
||||
return i, err
|
||||
}
|
||||
func (obj *readWriteCloser) Proxys() []Address {
|
||||
@@ -28,6 +34,7 @@ func (obj *readWriteCloser) Proxys() []Address {
|
||||
var errGospiderBodyClose = errors.New("gospider body close error")
|
||||
|
||||
func (obj *readWriteCloser) Close() (err error) {
|
||||
obj.isClosed = true
|
||||
obj.conn.bodyCnl(errGospiderBodyClose)
|
||||
return obj.body.Close() //reuse conn
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user