This is an automated email from the ASF dual-hosted git repository.
jamesthomas pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-client-js.git
The following commit(s) were added to refs/heads/master by this push:
new 31d729f add User-Agent to request header (#118)
31d729f is described below
commit 31d729f5c1e7686af213dc3f2717716ea58ff1ad
Author: Nick Mitchell <[email protected]>
AuthorDate: Fri May 25 04:31:00 2018 -0400
add User-Agent to request header (#118)
Fixes #117
---
README.md | 13 +++++++++++++
lib/client.js | 1 +
test/unit/actions.test.js | 15 +++++++++++++++
3 files changed, 29 insertions(+)
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})
+})
--
To stop receiving notification emails like this one, please contact
[email protected].