mirror of
https://github.com/gospider007/requests.git
synced 2025-12-24 13:57:52 +08:00
sync
This commit is contained in:
12
client.go
12
client.go
@@ -69,15 +69,3 @@ func (obj *Client) Close() {
|
||||
obj.CloseConns()
|
||||
obj.cnl()
|
||||
}
|
||||
func (obj *Client) send(ctx *Response) (err error) {
|
||||
if ctx.Option().Jar != nil {
|
||||
addCookie(ctx.Request(), ctx.Option().Jar.GetCookies(ctx.Request().URL))
|
||||
}
|
||||
err = obj.transport.RoundTrip(ctx)
|
||||
if ctx.Option().Jar != nil && ctx.response != nil {
|
||||
if rc := ctx.response.Cookies(); len(rc) > 0 {
|
||||
ctx.Option().Jar.SetCookies(ctx.Request().URL, rc)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
12
http.go
12
http.go
@@ -41,16 +41,6 @@ type clientConn struct {
|
||||
closeCtx context.Context
|
||||
closeCnl context.CancelCauseFunc
|
||||
}
|
||||
type httpBody struct {
|
||||
r *io.PipeReader
|
||||
}
|
||||
|
||||
func (obj *httpBody) Read(b []byte) (i int, err error) {
|
||||
return obj.r.Read(b)
|
||||
}
|
||||
func (obj *httpBody) Close() error {
|
||||
return obj.r.Close()
|
||||
}
|
||||
|
||||
func newClientConn(ctx context.Context, con net.Conn, closeFunc func(error)) *clientConn {
|
||||
closeCtx, closeCnl := context.WithCancelCause(ctx)
|
||||
@@ -116,7 +106,7 @@ func (obj *clientConn) send() {
|
||||
}
|
||||
}
|
||||
}()
|
||||
obj.task.res.Body = &httpBody{r: pr}
|
||||
obj.task.res.Body = pr
|
||||
}
|
||||
|
||||
func (obj *clientConn) CloseCtx() context.Context {
|
||||
|
||||
14
requests.go
14
requests.go
@@ -317,6 +317,11 @@ func (obj *Client) request(ctx *Response) (err error) {
|
||||
if cookies != nil {
|
||||
addCookie(reqs, cookies)
|
||||
}
|
||||
if ctx.Option().Jar != nil {
|
||||
addCookie(reqs, ctx.Option().Jar.GetCookies(reqs.URL))
|
||||
}
|
||||
//init cookies ok
|
||||
|
||||
if err = ctx.option.initSpec(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -324,7 +329,13 @@ func (obj *Client) request(ctx *Response) (err error) {
|
||||
//init spec
|
||||
|
||||
//send req
|
||||
err = obj.send(ctx)
|
||||
err = obj.transport.RoundTrip(ctx)
|
||||
if ctx.Option().Jar != nil && ctx.response != nil {
|
||||
if rc := ctx.response.Cookies(); len(rc) > 0 {
|
||||
ctx.Option().Jar.SetCookies(ctx.Request().URL, rc)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil && err != ErrUseLastResponse {
|
||||
err = tools.WrapError(err, "client do error")
|
||||
return
|
||||
@@ -350,6 +361,5 @@ func (obj *Client) request(ctx *Response) (err error) {
|
||||
ctx.response.Body = unCompressionBody
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user