Skip to content

Commit

Permalink
chore: remove duplicate setting of header params (#249)
Browse files Browse the repository at this point in the history
* chore: remove duplicate setting of header params

* chore: fixed client test by adding contentType
  • Loading branch information
tiwarishubham635 authored Jun 20, 2024
1 parent a489a1c commit f73a06f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 1 addition & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (c *Client) SendRequest(method string, rawURL string, data url.Values,

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

}

if contentType == urlEncodedContentType {
req.Header.Add("Content-Type", urlEncodedContentType)
}

req.SetBasicAuth(c.basicAuth())

// E.g. "User-Agent": "twilio-go/1.0.0 (darwin amd64) go/go1.17.8"
Expand Down
5 changes: 4 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ func TestClient_SendRequestWithData(t *testing.T) {
t.Run(tc, func(t *testing.T) {
data := url.Values{}
data.Set("foo", "bar")
resp, err := testClient.SendRequest(tc, dataServer.URL, data, nil) //nolint:bodyclose
headers := map[string]interface{}{
"Content-Type": "application/x-www-form-urlencoded",
}
resp, err := testClient.SendRequest(tc, dataServer.URL, data, headers) //nolint:bodyclose
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
})
Expand Down

0 comments on commit f73a06f

Please sign in to comment.