lib/pxproxy.js
function getCaptcha(req, config, ip, reversePrefix, cb) {
    let res = {};
    if (!config.FIRST_PARTY_ENABLED) {
        res = {
            status: 200,
            header: {key: 'Content-Type', value:'application/javascript'},
            body: ''
        };
        return cb(null, res);
    } else {
        const searchMask = `/${reversePrefix}${config.FIRST_PARTY_CAPTCHA_PATH}`;
        const regEx = new RegExp(searchMask, 'ig');
        const pxRequestUri =  `/${config.PX_APP_ID}${req.originalUrl.replace(regEx, '')}`;
        config.logger.debug(`Forwarding request from ${req.originalUrl} to xhr at ${config.CAPTCHA_HOST}${pxRequestUri}`);
        const callData = {
            url: `https://${config.CAPTCHA_HOST}${pxRequestUri}`,
            headers: pxUtil.filterSensitiveHeaders(req.headers, config.SENSITIVE_HEADERS),
            timeout: config.API_TIMEOUT_MS
        };
        callData.headers['host'] = config.CAPTCHA_HOST;
        callData.headers[config.ENFORCER_TRUE_IP_HEADER] = ip;
        callData.headers[config.FIRST_PARTY_HEADER] = 1;
        request.get(callData, config, (error, response) => {
            if (error || !response) {
                config.logger.error(`Error while fetching first party captcha: ${error}`);
            }

            response = response || {statusCode: 200, headers: {}};
            res = {
                status: response.statusCode,
                headers: response.headers,
                body: response.body || ''
            };
            return cb(null, res);
        });
    }
    return;
}
function getCaptcha(req, config, ip, reversePrefix, cb) {
    let res = {};
    if (!config.FIRST_PARTY_ENABLED) {
        res = {
            status: 200,
            header: {key: 'Content-Type', value:'application/javascript'},
            body: ''
        };
        return cb(null, res);
    } else {
        const searchMask = `/${reversePrefix}${config.FIRST_PARTY_CAPTCHA_PATH}`;
        const regEx = new RegExp(searchMask, 'ig');
        const pxRequestUri =  `/${config.PX_APP_ID}${req.originalUrl.replace(regEx, '')}`;
        config.logger.debug(`Forwarding request from ${req.originalUrl} to xhr at ${config.CAPTCHA_HOST}${pxRequestUri}`);
        const callData = {
            url: `https://${config.CAPTCHA_HOST}${pxRequestUri}`,
            headers: pxUtil.filterSensitiveHeaders(req.headers, config.SENSITIVE_HEADERS),
            timeout: config.API_TIMEOUT_MS
        };
        callData.headers['host'] = config.CAPTCHA_HOST;
        callData.headers[config.ENFORCER_TRUE_IP_HEADER] = ip;
        callData.headers[config.FIRST_PARTY_HEADER] = 1;
        request.get(callData, config, (error, response) => {
            if (error || !response) {
                config.logger.error(`Error while fetching first party captcha: ${error}`);
            }

            response = response || {statusCode: 200, headers: {}};
            res = {
                status: response.statusCode,
                headers: response.headers,
                body: response.body || ''
            };
            return cb(null, res);
        });
    }
    return;
}
function getCaptcha ( req , config , ip , reversePrefix , cb ) { let res = { } ; if ( ! config . FIRST_PARTY_ENABLED ) { res = { status : 200 , header : { key : 'Content-Type' , value : 'application/javascript' } , body : '' } ; return cb ( null , res ) ; } else { const searchMask = ` ${ reversePrefix } ${ config . FIRST_PARTY_CAPTCHA_PATH } ` ; const regEx = new RegExp ( searchMask , 'ig' ) ; const pxRequestUri = ` ${ config . PX_APP_ID } ${ req . originalUrl . replace ( regEx , '' ) } ` ; config . logger . debug ( ` ${ req . originalUrl } ${ config . CAPTCHA_HOST } ${ pxRequestUri } ` ) ; const callData = { url : ` ${ config . CAPTCHA_HOST } ${ pxRequestUri } ` , headers : pxUtil . filterSensitiveHeaders ( req . headers , config . SENSITIVE_HEADERS ) , timeout : config . API_TIMEOUT_MS } ; callData . headers [ 'host' ] = config . CAPTCHA_HOST ; callData . headers [ config . ENFORCER_TRUE_IP_HEADER ] = ip ; callData . headers [ config . FIRST_PARTY_HEADER ] = 1 ; request . get ( callData , config , ( error , response ) => { if ( error || ! response ) { config . logger . error ( ` ${ error } ` ) ; } response = response || { statusCode : 200 , headers : { } } ; res = { status : response . statusCode , headers : response . headers , body : response . body || '' } ; return cb ( null , res ) ; } ) ; } return ; }
getClient - process the proxy request to get the captcha script file from PX servers.

@param {object} req - the request object.
@param {object} config - the PerimeterX config object.
@param {string} ip - the ip that initiated the call.
@param {string} reversePrefix - the prefix of the xhr request.
@param {function} cb - the callback function to call at the end of the process.

@return {function} the callback function passed as param with the server response (captcha file) or error.
getClient - process the proxy request to get the captcha script file from PX servers .