This is an automated email from the ASF dual-hosted git repository.

dubeejw pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-go.git


The following commit(s) were added to refs/heads/master by this push:
     new 012fd0f  Additional HTTP Headers (#67)
012fd0f is described below

commit 012fd0fb022fd542fdd7606567d0c9b38ca56bd8
Author: James Dubee <jwdu...@us.ibm.com>
AuthorDate: Wed Mar 7 23:13:59 2018 -0500

    Additional HTTP Headers (#67)
    
    * Allow Additional HTTP Headers
    
    * Add AdditionalHeader Tests
    
    * Use http.Header as AdditionalHeader type
---
 whisk/client.go      | 33 +++++++++++++++++++++------------
 whisk/client_test.go | 28 ++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/whisk/client.go b/whisk/client.go
index d4e8afc..7b4862f 100644
--- a/whisk/client.go
+++ b/whisk/client.go
@@ -74,18 +74,19 @@ type Client struct {
 }
 
 type Config struct {
-       Namespace        string // NOTE :: Default is "_"
-       Cert             string
-       Key              string
-       AuthToken        string
-       Host             string
-       BaseURL          *url.URL // NOTE :: Default is 
"openwhisk.ng.bluemix.net"
-       Version          string
-       Verbose          bool
-       Debug            bool // For detailed tracing
-       Insecure         bool
-       UserAgent        string
-       ApigwAccessToken string
+       Namespace         string // NOTE :: Default is "_"
+       Cert              string
+       Key               string
+       AuthToken         string
+       Host              string
+       BaseURL           *url.URL // NOTE :: Default is 
"openwhisk.ng.bluemix.net"
+       Version           string
+       Verbose           bool
+       Debug             bool // For detailed tracing
+       Insecure          bool
+       UserAgent         string
+       ApigwAccessToken  string
+       AdditionalHeaders http.Header
 }
 
 type ObfuscateSet struct {
@@ -283,6 +284,10 @@ func (c *Client) NewRequest(method, urlStr string, body 
interface{}, includeName
 
        req.Header.Add("User-Agent", c.Config.UserAgent)
 
+       for key := range c.Config.AdditionalHeaders {
+               req.Header.Add(key, c.Config.AdditionalHeaders.Get(key))
+       }
+
        return req, nil
 }
 
@@ -778,5 +783,9 @@ func (c *Client) NewRequestUrl(
 
        req.Header.Add("User-Agent", c.Config.UserAgent)
 
+       for key := range c.Config.AdditionalHeaders {
+               req.Header.Add(key, c.Config.AdditionalHeaders.Get(key))
+       }
+
        return req, nil
 }
diff --git a/whisk/client_test.go b/whisk/client_test.go
index 1752b40..ec27b63 100644
--- a/whisk/client_test.go
+++ b/whisk/client_test.go
@@ -140,3 +140,31 @@ func TestProxyHost(t *testing.T) {
                assert.Contains(t, err.Error(), proxyhost, "Setting HTTPS_PROXY 
to '"+proxyhost+"' did not cause the CLI to use that proxy URL.")
        }
 }
+
+func TestAdditionalHeaders(t *testing.T) {
+       config := GetValidConfigTest()
+       config.AdditionalHeaders = make(map[string][]string)
+       config.AdditionalHeaders.Add("Key1", "Value1")
+       config.AdditionalHeaders.Add("Key2", "Value2")
+
+       client, _ := NewClient(nil, config)
+       assert.NotNil(t, client)
+
+       newRequest, newRequestErr := client.NewRequest("GET", 
config.BaseURL.String(), nil, false)
+       assert.Nil(t, newRequestErr, "NewRequest for proxy test failed.")
+       if newRequestErr != nil {
+               fmt.Printf("NewRequest() error: %s\n", newRequestErr.Error())
+       }
+
+       assert.Equal(t, "Value1", newRequest.Header.Get("Key1"))
+       assert.Equal(t, "Value2", newRequest.Header.Get("Key2"))
+
+       newRequestUrl, newRequestUrlErr := client.NewRequestUrl("GET", 
config.BaseURL, nil, false, false, "", false)
+       assert.Nil(t, newRequestUrlErr, "NewRequest for proxy test failed.")
+       if newRequestUrlErr != nil {
+               fmt.Printf("NewRequest() error: %s\n", newRequestUrlErr.Error())
+       }
+
+       assert.Equal(t, "Value1", newRequestUrl.Header.Get("Key1"))
+       assert.Equal(t, "Value2", newRequestUrl.Header.Get("Key2"))
+}

-- 
To stop receiving notification emails like this one, please contact
dube...@apache.org.

Reply via email to