forked from watson-developer-cloud/speech-javascript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquerystring.js
More file actions
19 lines (18 loc) · 749 Bytes
/
querystring.js
File metadata and controls
19 lines (18 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
/**
* Stringify query params, Watson-style
*
* Why? The server that processes auth tokens currently only accepts the *exact* string, even if it's invalid for a URL.
* Properly url-encoding percent characters causes it to reject the token.
* So, this is a custom qs.stringify function that properly encodes everything except watson-token, passing it along verbatim
*
* @param {Object} queryParams
* @return {String}
*/
exports.stringify = function stringify(queryParams) {
return Object.keys(queryParams)
.map(function(key) {
return key + '=' + (key === 'watson-token' ? queryParams[key] : encodeURIComponent(queryParams[key])); // the server chokes if the token is correctly url-encoded
})
.join('&');
};