mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/http: close resp.Body when error occurred during redirection
Fixes #19976 Change-Id: I48486467066784a9dcc24357ec94a1be85265a6f Reviewed-on: https://go-review.googlesource.com/40940 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
2b6c58f6d5
commit
e51e0f9cdd
2 changed files with 9 additions and 0 deletions
|
|
@ -524,10 +524,12 @@ func (c *Client) Do(req *Request) (*Response, error) {
|
|||
if len(reqs) > 0 {
|
||||
loc := resp.Header.Get("Location")
|
||||
if loc == "" {
|
||||
resp.closeBody()
|
||||
return nil, uerr(fmt.Errorf("%d response missing Location header", resp.StatusCode))
|
||||
}
|
||||
u, err := req.URL.Parse(loc)
|
||||
if err != nil {
|
||||
resp.closeBody()
|
||||
return nil, uerr(fmt.Errorf("failed to parse Location header %q: %v", loc, err))
|
||||
}
|
||||
ireq := reqs[0]
|
||||
|
|
@ -542,6 +544,7 @@ func (c *Client) Do(req *Request) (*Response, error) {
|
|||
if includeBody && ireq.GetBody != nil {
|
||||
req.Body, err = ireq.GetBody()
|
||||
if err != nil {
|
||||
resp.closeBody()
|
||||
return nil, uerr(err)
|
||||
}
|
||||
req.ContentLength = ireq.ContentLength
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue