Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove duplicate setting of header params #249

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading