From 75fc71ccb45de71d921129d83d8207ac8eed7e41 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Tue, 18 Dec 2018 01:42:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=91=E9=99=8B=E7=9A=84=E8=A7=A3=E5=8E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- response.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/response.go b/response.go index 77477d3..bf7acdd 100644 --- a/response.go +++ b/response.go @@ -37,23 +37,30 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) { srcReader := bytes.NewReader(srcbuf) r, err := gzip.NewReader(srcReader) - defer r.Close() if err == nil { + defer r.Close() buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) } else { + if r != nil { + r.Close() + } + r, err := zlib.NewReader(srcReader) - defer r.Close() if err == nil { + defer r.Close() buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) } else { + if r != nil { + r.Close() + } content = string(srcbuf) } }