diff --git a/go.sum b/go.sum index e518a62..eb6e194 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= diff --git a/soup.go b/soup.go index d504361..3b11fcb 100644 --- a/soup.go +++ b/soup.go @@ -125,7 +125,11 @@ func GetWithClient(url string, client *http.Client) (string, error) { return "", newError(ErrInGetRequest, "couldn't perform GET request to "+url) } defer resp.Body.Close() - bytes, err := ioutil.ReadAll(resp.Body) + utf8Body, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type")) + if err != nil { + return "", err + } + bytes, err := ioutil.ReadAll(utf8Body) if err != nil { if debug { panic("Unable to read the response body") @@ -210,12 +214,7 @@ func PostWithClient(url string, bodyType string, body interface{}, client *http. return "", newError(ErrCreatingPostRequest, "couldn't perform POST request to"+url) } defer resp.Body.Close() - - utf8Body, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type")) - if err != nil { - return "", err - } - bytes, err := ioutil.ReadAll(utf8Body) + bytes, err := ioutil.ReadAll(resp.Body) if err != nil { if debug { panic("Unable to read the response body")