jthomas closed pull request #118: add User-Agent to request header
URL: https://github.com/apache/incubator-openwhisk-client-js/pull/118
 
 
   

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/README.md b/README.md
index cdaa050..74df04e 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,20 @@ Client constructor will read values for the `apihost`, 
`namespace`, `api_key`, `
 - *__OW_APIGW_TOKEN*
 - *__OW_APIGW_SPACE_SUID*
 
+### User-Agent
 
+A User-Agent header may be specified to be passed along with all calls
+to OpenWhisk. This can be helpful, if you wish to discriminate client
+traffic to your OpenWhisk backend. By default, the header will have
+the value `openwhisk-client-js`. You may override this by passing
+along a `'User-Agent'` field in the options structure of any API
+calls; note that this is *not* a constructor argument, but rather an
+option to the API calls themselves. For example, one might specify a
+`myClient` user agent to an action invocation as follows:
+
+```javascript
+ow.actions.invoke({ 'User-Agent': 'myClient', name, params })
+```
 
 ## Examples
 
diff --git a/lib/client.js b/lib/client.js
index 900173c..48723e3 100644
--- a/lib/client.js
+++ b/lib/client.js
@@ -124,6 +124,7 @@ class Client {
       url: this.pathUrl(path),
       rejectUnauthorized: !this.options.ignoreCerts,
       headers: {
+        'User-Agent': (options && options['User-Agent']) || 
'openwhisk-client-js',
         Authorization: this.authHeader()
       }
     }, options)
diff --git a/test/unit/actions.test.js b/test/unit/actions.test.js
index 8d3140f..c3a6455 100644
--- a/test/unit/actions.test.js
+++ b/test/unit/actions.test.js
@@ -429,3 +429,18 @@ test('create a new action with version parameter', t => {
 
   return actions.create({name: '12345', action, version})
 })
+
+test('should pass through requested User-Agent header', t => {
+  t.plan(1)
+  const userAgent = 'userAgentShouldPassThroughPlease'
+  const client = {}
+  const actions = new Actions(client)
+  const action = 'function main() { // main function body};'
+  const version = '1.0.0'
+
+  client.request = (method, path, options) => {
+    t.is(options['User-Agent'], userAgent)
+  }
+
+  return actions.create({name: '12345', action, version, 'User-Agent': 
userAgent})
+})


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to