aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-06-19 17:48:04 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-06-19 17:49:21 +0200
commit5fc859eabd5c2e38b10cbb63f057e83da0748831 (patch)
tree4be7b26bf6df79660489b3200a9fe7b3429bc667
parent4cdfdb2b5987b456f7ce72217293e02d4fe7b5ea (diff)
Change-Id: I1f1dcb613c685aeac9981d85460b7899bb323a4d Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-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)
}