Skip to content

Commit a6205c6

Browse files
committed
allow to overwrite content-type
1 parent 5452733 commit a6205c6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

client.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,29 @@ func (c *Client) SetApiBaseURL(urlStr url.URL) {
173173
}
174174

175175
func (c *Client) executeRaw(method string, urlStr string, text string) (io.ReadCloser, error) {
176+
return c.executeRawContentType(method, urlStr, text, "application/json")
177+
}
178+
179+
func (c *Client) executeRawContentType(method, urlStr, text, contentType string) (io.ReadCloser, error) {
176180
body := strings.NewReader(text)
177181

178182
req, err := http.NewRequest(method, urlStr, body)
179183
if err != nil {
180184
return nil, err
181185
}
182186
if text != "" {
183-
req.Header.Set("Content-Type", "application/json")
187+
req.Header.Set("Content-Type", contentType)
184188
}
185189

186190
c.authenticateRequest(req)
187191
return c.doRawRequest(req, false)
188192
}
189193

190194
func (c *Client) execute(method string, urlStr string, text string) (interface{}, error) {
195+
return c.executeContentType(method, urlStr, text, "application/json")
196+
}
197+
198+
func (c *Client) executeContentType(method string, urlStr string, text string, contentType string) (interface{}, error) {
191199
// Use pagination if changed from default value
192200
const DEC_RADIX = 10
193201
if strings.Contains(urlStr, "/repositories/") {
@@ -221,7 +229,7 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
221229
return nil, err
222230
}
223231
if text != "" {
224-
req.Header.Set("Content-Type", "application/json")
232+
req.Header.Set("Content-Type", contentType)
225233
}
226234

227235
c.authenticateRequest(req)

0 commit comments

Comments
 (0)