Skip to content

Commit bfaac38

Browse files
committed
allow to overwrite content-type
1 parent b8bc8c9 commit bfaac38

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,29 @@ func (c *Client) SetApiBaseURL(urlStr string) {
164164
}
165165

166166
func (c *Client) executeRaw(method string, urlStr string, text string) (io.ReadCloser, error) {
167+
return c.executeRawContentType(method, urlStr, text, "application/json")
168+
}
169+
170+
func (c *Client) executeRawContentType(method, urlStr, text, contentType string) (io.ReadCloser, error) {
167171
body := strings.NewReader(text)
168172

169173
req, err := http.NewRequest(method, urlStr, body)
170174
if err != nil {
171175
return nil, err
172176
}
173177
if text != "" {
174-
req.Header.Set("Content-Type", "application/json")
178+
req.Header.Set("Content-Type", contentType)
175179
}
176180

177181
c.authenticateRequest(req)
178182
return c.doRawRequest(req, false)
179183
}
180184

181185
func (c *Client) execute(method string, urlStr string, text string) (interface{}, error) {
186+
return c.executeContentType(method, urlStr, text, "application/json")
187+
}
188+
189+
func (c *Client) executeContentType(method string, urlStr string, text string, contentType string) (interface{}, error) {
182190
// Use pagination if changed from default value
183191
const DEC_RADIX = 10
184192
if strings.Contains(urlStr, "/repositories/") {
@@ -212,7 +220,7 @@ func (c *Client) execute(method string, urlStr string, text string) (interface{}
212220
return nil, err
213221
}
214222
if text != "" {
215-
req.Header.Set("Content-Type", "application/json")
223+
req.Header.Set("Content-Type", contentType)
216224
}
217225

218226
c.authenticateRequest(req)

0 commit comments

Comments
 (0)