Skip to content
Open
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
22 changes: 9 additions & 13 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ func (r *marathonClient) apiCall(method, path string, body, result interface{})
return err
}

// Might suffice to set Content-Type if body is non-nil and Accept if
// result is non-nil. Without integration tests, however, we'll play
// it safe.
if body != nil || result != nil {
request.Header.Add("Content-Type", "application/json")
request.Header.Add("Accept", "application/json")
}

// step: perform the API request
response, err := r.client.Do(request)
if err != nil {
Expand Down Expand Up @@ -357,25 +365,13 @@ func (r *marathonClient) buildAPIRequest(method, path string, reader io.Reader)
}

// Build the HTTP request to Marathon
request, err = r.client.buildMarathonJSONRequest(method, member, path, reader)
request, err = r.client.buildMarathonRequest(method, member, path, reader)
if err != nil {
return nil, member, newRequestError{err}
}
return request, member, nil
}

// buildMarathonJSONRequest is like buildMarathonRequest but sets the
// Content-Type and Accept headers to application/json.
func (rc *httpClient) buildMarathonJSONRequest(method, member, path string, reader io.Reader) (request *http.Request, err error) {
req, err := rc.buildMarathonRequest(method, member, path, reader)
if err == nil {
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Accept", "application/json")
}

return req, err
}

// buildMarathonRequest creates a new HTTP request and configures it according to the *httpClient configuration.
// The path must not contain a leading "/", otherwise buildMarathonRequest will panic.
func (rc *httpClient) buildMarathonRequest(method, member, path string, reader io.Reader) (request *http.Request, err error) {
Expand Down