aboutsummaryrefslogtreecommitdiffstats
path: root/golib/httpclient.go
diff options
context:
space:
mode:
Diffstat (limited to 'golib/httpclient.go')
-rw-r--r--golib/httpclient.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/golib/httpclient.go b/golib/httpclient.go
index 6662b2d..f4880e6 100644
--- a/golib/httpclient.go
+++ b/golib/httpclient.go
@@ -33,6 +33,7 @@ type HTTPClient struct {
// HTTPClientConfig is used to config HTTPClient
type HTTPClientConfig struct {
URLPrefix string
+ ContentType string
HeaderAPIKeyName string
Apikey string
HeaderClientKeyName string
@@ -87,6 +88,11 @@ func HTTPNewClient(baseURL string, cfg HTTPClientConfig) (*HTTPClient, error) {
*/
}
+ // Default set Content-Type to json
+ if client.conf.ContentType == "" {
+ client.conf.ContentType = "application/json"
+ }
+
if err := client.getCidAndCsrf(); err != nil {
client.log(HTTPLogLevelError, "Cannot retrieve Client ID and/or CSRF: %v", err)
return &client, err
@@ -293,6 +299,9 @@ func (c *HTTPClient) _HTTPRequest(method, url string, body *string, data *[]byte
}
func (c *HTTPClient) handleRequest(request *http.Request) (*http.Response, error) {
+ if c.conf.ContentType != "" {
+ request.Header.Set("Content-Type", c.conf.ContentType)
+ }
if c.conf.HeaderAPIKeyName != "" && c.apikey != "" {
request.Header.Set(c.conf.HeaderAPIKeyName, c.apikey)
}