diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-06-19 17:48:04 +0200 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-06-19 17:49:21 +0200 |
commit | 5fc859eabd5c2e38b10cbb63f057e83da0748831 (patch) | |
tree | 4be7b26bf6df79660489b3200a9fe7b3429bc667 | |
parent | 4cdfdb2b5987b456f7ce72217293e02d4fe7b5ea (diff) |
Set Content-Type to json in httpclient libhalibut_7.90.0halibut/7.90.0guppy_6.99.4guppy_6.99.3guppy_6.99.2guppy_6.99.1guppy_6.90.0guppy/6.99.4guppy/6.99.3guppy/6.99.2guppy/6.99.1guppy/6.90.0flounder_5.99.6flounder_5.99.5flounder_5.99.3flounder_5.99.2flounder_5.99.1flounder/5.99.6flounder/5.99.5flounder/5.99.3flounder/5.99.2flounder/5.99.17.90.06.99.46.99.36.99.26.99.16.90.05.99.65.99.55.99.35.99.25.99.1
Change-Id: I1f1dcb613c685aeac9981d85460b7899bb323a4d
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r-- | golib/httpclient.go | 9 |
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) } |