Skip to content

Commit cb47551

Browse files
committed
moving utf8 charset transformation from POST to GET func
1 parent cf37ece commit cb47551

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
1010
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
1111
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
1212
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
13+
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
1314
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
1415
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1516
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

soup.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ func GetWithClient(url string, client *http.Client) (string, error) {
125125
return "", newError(ErrInGetRequest, "couldn't perform GET request to "+url)
126126
}
127127
defer resp.Body.Close()
128-
bytes, err := ioutil.ReadAll(resp.Body)
128+
utf8Body, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type"))
129+
if err != nil {
130+
return "", err
131+
}
132+
bytes, err := ioutil.ReadAll(utf8Body)
129133
if err != nil {
130134
if debug {
131135
panic("Unable to read the response body")
@@ -210,12 +214,7 @@ func PostWithClient(url string, bodyType string, body interface{}, client *http.
210214
return "", newError(ErrCreatingPostRequest, "couldn't perform POST request to"+url)
211215
}
212216
defer resp.Body.Close()
213-
214-
utf8Body, err := charset.NewReader(resp.Body, resp.Header.Get("Content-Type"))
215-
if err != nil {
216-
return "", err
217-
}
218-
bytes, err := ioutil.ReadAll(utf8Body)
217+
bytes, err := ioutil.ReadAll(resp.Body)
219218
if err != nil {
220219
if debug {
221220
panic("Unable to read the response body")

0 commit comments

Comments
 (0)