Skip to content

Commit

Permalink
switched the point to add headers and make a function
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy committed Oct 19, 2023
1 parent e3f6fb5 commit a233abd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/services/sf.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,14 @@ function StateAbstract(options)
requestOptions.headers =
Util.apply(this.getDefaultReqHeaders(), requestOptions.headers || {});

if (Util.isLoginRequest(requestOptions.url)) {
Util.apply(requestOptions.headers, {
"CLIENT_APP_VERSION": requestOptions.json.data.CLIENT_APP_VERSION,
"CLIENT_APP_ID": requestOptions.json.data.CLIENT_APP_ID,
})

}

// augment the options with the absolute url
requestOptions.absoluteUrl = this.buildFullUrl(requestOptions.url);
};
Expand Down Expand Up @@ -1242,10 +1250,6 @@ StateConnecting.prototype.continue = function ()
const sendRequest = function ()
{
const targetUrl = buildLoginUrl(connectionConfig);
const headers = {
"CLIENT_APP_VERSION": connectionConfig.getClientVersion(),
"CLIENT_APP_ID": "JavaScript",
}
Logger.getInstance().debug(
"Contacting SF: %s, (%s/%s)", targetUrl, numRetries, maxLoginRetries);
const request = parent.createUnauthenticatedRequest({
Expand All @@ -1255,7 +1259,6 @@ StateConnecting.prototype.continue = function ()
scope: this,
startTime: startTime,
retry: numRetries,
headers: headers,
callback: requestCallback
});
request.send();
Expand Down
7 changes: 6 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,14 @@ function getJitter (curWaitTime) {
}

function chooseRandom (firstNumber, secondNumber) {
const random = Math.floor(Math.random()*1000);
const random = Math.floor(Math.random() * 1000);
return random % 2 === 0 ? firstNumber : secondNumber;
}

exports.isLoginRequest = function (loginUrl) {
const endPoints = ['/v1/login-request', '/authenticator-request', '/token-request',];
return endPoints.some((endPoint) => loginUrl.includes(endPoint));
}
/**
* Checks if the HTTP response code is retryable
*
Expand Down

0 comments on commit a233abd

Please sign in to comment.