mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Move Content-Type header setting to doJSON() in Portainer client
This commit is contained in:
parent
14043a8bf8
commit
19f58c4e1f
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user