You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/08 04:14:01 UTC

[GitHub] dubeejw closed pull request #67: Additional HTTP Headers

dubeejw closed pull request #67: Additional HTTP Headers
URL: https://github.com/apache/incubator-openwhisk-client-go/pull/67
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/whisk/client.go b/whisk/client.go
index d4e8afcf..7b4862ff 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 1752b40f..ec27b63f 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"))
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services