Move Content-Type header setting to doJSON() in Portainer client

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-24 09:05:34 -04:00
parent 14043a8bf8
commit 19f58c4e1f
2 changed files with 9 additions and 9 deletions

View File

@ -104,7 +104,7 @@ func checkResponseForErrors(resp *http.Response) error {
}
// Do an http request
func (n *portainerClientImp) do(uri, method string, request io.Reader, requestType string, headers http.Header) (resp *http.Response, err error) {
func (n *portainerClientImp) do(uri, method string, request io.Reader, headers http.Header) (resp *http.Response, err error) {
requestURL, err := n.url.Parse(uri)
if err != nil {
return
@ -120,7 +120,6 @@ func (n *portainerClientImp) do(uri, method string, request io.Reader, requestTy
}
if request != nil {
req.Header.Set("Content-Type", requestType)
req.Header.Set("User-Agent", n.userAgent)
}
@ -165,7 +164,9 @@ func (n *portainerClientImp) doJSON(uri, method string, headers http.Header, req
body = bytes.NewReader(reqBodyBytes)
}
resp, err := n.do(uri, method, body, "application/json", headers)
headers.Set("Content-Type", "application/json")
resp, err := n.do(uri, method, body, headers)
if err != nil {
return err
}

View File

@ -85,11 +85,10 @@ func Test_portainerClientImp_do(t *testing.T) {
beforeFunctionCall func(t *testing.T, tt *fields)
}
type args struct {
uri string
method string
request io.Reader
requestType string
headers http.Header
uri string
method string
request io.Reader
headers http.Header
}
tests := []struct {
name string
@ -175,7 +174,7 @@ func Test_portainerClientImp_do(t *testing.T) {
if tt.fields.beforeFunctionCall != nil {
tt.fields.beforeFunctionCall(t, &tt.fields)
}
gotResp, err := n.do(tt.args.uri, tt.args.method, tt.args.request, tt.args.requestType, tt.args.headers)
gotResp, err := n.do(tt.args.uri, tt.args.method, tt.args.request, tt.args.headers)
assert.Equal(t, tt.wantErr, err != nil)
if tt.wantRespCheck != nil {