mirror of
https://github.com/golang/go
synced 2024-11-22 00:34:40 -07:00
http: close underlying gzip Reader too
Fixes #1724 R=rsc CC=golang-dev https://golang.org/cl/4443056
This commit is contained in:
parent
a1f5f3f109
commit
750b6c63f9
@ -532,12 +532,12 @@ func (pc *persistConn) roundTrip(req *Request) (resp *Response, err os.Error) {
|
||||
re.res.Header.Del("Content-Encoding")
|
||||
re.res.Header.Del("Content-Length")
|
||||
re.res.ContentLength = -1
|
||||
var err os.Error
|
||||
re.res.Body, err = gzip.NewReader(re.res.Body)
|
||||
gzReader, err := gzip.NewReader(re.res.Body)
|
||||
if err != nil {
|
||||
pc.close()
|
||||
return nil, err
|
||||
}
|
||||
re.res.Body = &readFirstCloseBoth{gzReader, re.res.Body}
|
||||
}
|
||||
|
||||
return re.res, re.err
|
||||
@ -606,3 +606,18 @@ func (es *bodyEOFSignal) Close() (err os.Error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type readFirstCloseBoth struct {
|
||||
io.ReadCloser
|
||||
io.Closer
|
||||
}
|
||||
|
||||
func (r *readFirstCloseBoth) Close() os.Error {
|
||||
if err := r.ReadCloser.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := r.Closer.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user