Skip to content

Commit f73a06f

Browse files
chore: remove duplicate setting of header params (#249)
* chore: remove duplicate setting of header params * chore: fixed client test by adding contentType
1 parent a489a1c commit f73a06f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

client/client.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values,
143143

144144
//For HTTP GET Method there are no body parameters. All other parameters like query, path etc
145145
// are added as information in the url itself. Also while Content-Type is json, we are sending
146-
// json body. In that case, data variable conatins all other parameters than body, which is the
146+
// json body. In that case, data variable contains all other parameters than body, which is the
147147
//same case as GET method. In that case as well all parameters will be added to url
148148
if method == http.MethodGet || contentType == jsonContentType {
149149
if data != nil {
@@ -178,10 +178,6 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values,
178178

179179
}
180180

181-
if contentType == urlEncodedContentType {
182-
req.Header.Add("Content-Type", urlEncodedContentType)
183-
}
184-
185181
req.SetBasicAuth(c.basicAuth())
186182

187183
// E.g. "User-Agent": "twilio-go/1.0.0 (darwin amd64) go/go1.17.8"

client/client_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ func TestClient_SendRequestWithData(t *testing.T) {
180180
t.Run(tc, func(t *testing.T) {
181181
data := url.Values{}
182182
data.Set("foo", "bar")
183-
resp, err := testClient.SendRequest(tc, dataServer.URL, data, nil) //nolint:bodyclose
183+
headers := map[string]interface{}{
184+
"Content-Type": "application/x-www-form-urlencoded",
185+
}
186+
resp, err := testClient.SendRequest(tc, dataServer.URL, data, headers) //nolint:bodyclose
184187
assert.NoError(t, err)
185188
assert.Equal(t, 200, resp.StatusCode)
186189
})

0 commit comments

Comments
 (0)