From e165b6a0a0a7598681277db3c574aac67806d04f Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Tue, 18 Dec 2018 01:36:18 +0800 Subject: [PATCH] test open files --- response.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/response.go b/response.go index 4176b10..77477d3 100644 --- a/response.go +++ b/response.go @@ -33,23 +33,29 @@ func FromHTTPResponse(resp *http.Response) (*Response, error) { // resp.Body = ioutil.NopCloser(cbuf) - content := string(srcbuf) + content := "" srcReader := bytes.NewReader(srcbuf) - if r, err := gzip.NewReader(srcReader); err == nil { - defer r.Close() + r, err := gzip.NewReader(srcReader) + defer r.Close() + if err == nil { buf, err := ioutil.ReadAll(r) if err != nil { panic(err) } content = string(buf) - } else if r, err := zlib.NewReader(srcReader); err == nil { + } else { + r, err := zlib.NewReader(srcReader) defer r.Close() - buf, err := ioutil.ReadAll(r) - if err != nil { - panic(err) + if err == nil { + buf, err := ioutil.ReadAll(r) + if err != nil { + panic(err) + } + content = string(buf) + } else { + content = string(srcbuf) } - content = string(buf) } return &Response{DContent: content, GResponse: resp}, nil