Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/pxapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function callServer(pxCtx, callback) {
}

pxCtx.hasMadeServerCall = true;
return pxHttpc.callServer(data, reqHeaders, config.SERVER_TO_SERVER_API_URI, 'query', false, callback);
return pxHttpc.callServer(data, reqHeaders, config.SERVER_TO_SERVER_API_URI, 'query', callback);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/pxclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class PxClient {
}

callServer(data, path, headers, cb) {
pxHttpc.callServer(data, headers, path, 'activities', true);
pxHttpc.callServer(data, headers, path, 'activities');
if (cb) {
cb();
}
Expand Down
5 changes: 2 additions & 3 deletions lib/pxhttpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module.exports = {
* @param {string} callType - indication for a query or activities sending
* @param {Function} callback - callback function.
*/
function callServer(data, headers, uri, callType, ignoreResponse, callback) {
callback = callback || ((err) => { pxLogger.debug(`callServer callback missing. Error: ${err}`) });
function callServer(data, headers, uri, callType, callback) {
callback = callback || ((err) => { err && pxLogger.debug(`callServer default callback. Error: ${err}`); });
const config = pxConfig.conf;
const callData = {
url: `https://${config.SERVER_HOST}${uri}`,
Expand All @@ -26,7 +26,6 @@ function callServer(data, headers, uri, callType, ignoreResponse, callback) {
};

callData.timeout = callType === 'query' ? config.API_TIMEOUT_MS : config.ACTIVITIES_TIMEOUT;
callData.ignoreResponse = ignoreResponse;

try {
request.post(callData, function (err, response) {
Expand Down
8 changes: 0 additions & 8 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ const request = {
function makeRequest(options, cb) {
options.agent = keepAliveAgent;
try {
if (options.ignoreResponse) {
return makeRequestWithNoResponse(options);
}
p(options, cb)
} catch (e) {
pxLogger.error(`Error making request: ${e.message}`);
}
}


function makeRequestWithNoResponse(options) {
p(options);
}

module.exports = request;
2 changes: 1 addition & 1 deletion test/pxapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('PX API - pxapi.js', () => {
let pxconfig = require('../lib/pxconfig');
pxconfig.init(params, new PxClient());
config = pxconfig.mergeDefaults(params);
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback(data)
});
});
Expand Down
3 changes: 2 additions & 1 deletion test/pxconfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ describe('PX Configurations - pxconfig.js', () => {
blockingScore: 60,
debugMode: true,
ipHeader: 'x-px-true-ip',
maxBufferLength: 1
maxBufferLength: 1,
customRequestHandler: null
};

pxconfig = require('../lib/pxconfig');
Expand Down
20 changes: 10 additions & 10 deletions test/pxenforcer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('enforces a call in a disabled module', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
params.enableModule = false;
Expand All @@ -56,7 +56,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('enforces a call in an enabled module', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
enforcer = new PxEnforcer(params, new PxClient());
Expand All @@ -67,8 +67,8 @@ describe('PX Enforcer - pxenforcer.js', () => {
});
});

it.only('uses first party to get client', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
it('uses first party to get client', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'get').callsFake((data, callback) => {
Expand All @@ -86,7 +86,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('uses first party for xhr post request', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'post').callsFake((data, callback) => {
Expand All @@ -106,7 +106,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('uses first party for xhr get request', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'get').callsFake((data, callback) => {
Expand All @@ -126,7 +126,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('uses first party with pxvid cookie', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'post').callsFake((data, callback) => {
Expand All @@ -147,7 +147,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('uses first party for xhr and passed trough bodyParser', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'post').callsFake((data, callback) => {
Expand All @@ -167,7 +167,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('uses upper case for xhr', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
return callback ? callback(null, data) : '';
});
let reqStub = sinon.stub(request, 'post').callsFake((data, callback) => {
Expand All @@ -187,7 +187,7 @@ describe('PX Enforcer - pxenforcer.js', () => {
});

it('should not use first party paths if originated from mobile', (done) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, ignore, callback) => {
stub = sinon.stub(pxhttpc, 'callServer').callsFake((data, headers, uri, callType, callback) => {
data.score = 100;
data.action = 'b';
return callback ? callback(null, data) : '';
Expand Down
Loading