Skip to content

Commit

Permalink
Merge pull request #23 from DavidCai1993/master
Browse files Browse the repository at this point in the history
handle deflate compressed response
  • Loading branch information
mozillazg authored Nov 7, 2016
2 parents fb2aa53 + 3ea31fa commit 71ec6a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Version export version
const Version = "0.6.0"
const Version = "0.7.0"

// DefaultClient for NewArgs and NewRequest
var DefaultClient = new(http.Client)
Expand Down
14 changes: 9 additions & 5 deletions response.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package request

import (
"compress/flate"
"compress/gzip"
"io"
"io/ioutil"
Expand Down Expand Up @@ -34,20 +35,23 @@ func (resp *Response) Content() (b []byte, err error) {
var reader io.ReadCloser
switch resp.Header.Get("Content-Encoding") {
case "gzip":
reader, err := gzip.NewReader(resp.Body)
if err != nil {
if reader, err = gzip.NewReader(resp.Body); err != nil {
return nil, err
}
b, err = ioutil.ReadAll(reader)

defer reader.Close()
case "deflate":
reader = flate.NewReader(resp.Body)

defer reader.Close()
default:
reader = resp.Body
b, err = ioutil.ReadAll(reader)
}

if err != nil {
if b, err = ioutil.ReadAll(reader); err != nil {
return nil, err
}

resp.content = b
return b, err
}
Expand Down

0 comments on commit 71ec6a1

Please sign in to comment.