diff --git a/client/client.go b/client/client.go index 1ee628d..36a458b 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } diff --git a/client/client_test.go b/client/client_test.go index 7ed88d0..e22294f 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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 {