diff --git a/src/pkg/http/transport.go b/src/pkg/http/transport.go index 6250880b158..afbccef4493 100644 --- a/src/pkg/http/transport.go +++ b/src/pkg/http/transport.go @@ -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 +}