Skip to content

Commit 75c6fbf

Browse files
author
Pat Patterson
committed
Merge pull request developerforce#15 from chexxor/master
Allow to set header for apexrest function.
2 parents 6514b30 + 5eb681a commit 75c6fbf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

forcetk.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ if (forcetk.Client === undefined) {
249249
* @param [error=null] function to which jqXHR will be passed in case of error
250250
* @param [method="GET"] HTTP method for call
251251
* @param [payload=null] payload for POST/PATCH etc
252+
* @param [paramMap={}] parameters to send as header values for POST/PATCH etc
253+
* @param [retry] specifies whether to retry on error
252254
*/
253-
forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, retry) {
255+
forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, paramMap, retry) {
254256
var that = this;
255257
var url = this.instanceUrl + '/services/apexrest' + path;
256258

@@ -268,7 +270,7 @@ if (forcetk.Client === undefined) {
268270
that.refreshAccessToken(function(oauthResponse) {
269271
that.setSessionToken(oauthResponse.access_token, null,
270272
oauthResponse.instance_url);
271-
that.ajax(path, callback, error, method, payload, true);
273+
that.apexrest(path, callback, error, method, payload, paramMap, true);
272274
},
273275
error);
274276
} else {
@@ -280,6 +282,13 @@ if (forcetk.Client === undefined) {
280282
if (that.proxyUrl !== null) {
281283
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
282284
}
285+
//Add any custom headers
286+
if (paramMap === null) {
287+
paramMap = {};
288+
}
289+
for (paramName in paramMap) {
290+
xhr.setRequestHeader(paramName, paramMap[paramName]);
291+
}
283292
xhr.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId);
284293
xhr.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
285294
}

0 commit comments

Comments
 (0)