Skip to content

Commit

Permalink
moving utf8 charset transformation from POST to GET func
Browse files Browse the repository at this point in the history
  • Loading branch information
anaskhan96 committed Sep 24, 2020
1 parent cf37ece commit cb47551
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
13 changes: 6 additions & 7 deletions soup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit cb47551

Please sign in to comment.