packages/optimizely-sdk/lib/plugins/event_dispatcher/index.node.js
function(eventObj, callback) {
    // Non-POST requests not supported
    if (eventObj.httpVerb !== 'POST') {
      return;
    }

    var parsedUrl = url.parse(eventObj.url);
    var path = parsedUrl.path;
    if (parsedUrl.query) {
      path += '?' + parsedUrl.query;
    }

    var dataString = JSON.stringify(eventObj.params);

    var requestOptions = {
      host: parsedUrl.host,
      path: parsedUrl.path,
      method: 'POST',
      headers: {
        'content-type': 'application/json',
        'content-length': dataString.length.toString(),
      }
    };

    var requestCallback = function(response) {
      if (response && response.statusCode && response.statusCode >= 200 && response.statusCode < 400) {
        callback(response);
      }
    };

    var req = (parsedUrl.protocol === 'http:' ? http : https).request(requestOptions, requestCallback);
    // Add no-op error listener to prevent this from throwing
    req.on('error', function() {});
    req.write(dataString);
    req.end();
    return req;
  }
function(eventObj, callback) {
    // Non-POST requests not supported
    if (eventObj.httpVerb !== 'POST') {
      return;
    }

    var parsedUrl = url.parse(eventObj.url);
    var path = parsedUrl.path;
    if (parsedUrl.query) {
      path += '?' + parsedUrl.query;
    }

    var dataString = JSON.stringify(eventObj.params);

    var requestOptions = {
      host: parsedUrl.host,
      path: parsedUrl.path,
      method: 'POST',
      headers: {
        'content-type': 'application/json',
        'content-length': dataString.length.toString(),
      }
    };

    var requestCallback = function(response) {
      if (response && response.statusCode && response.statusCode >= 200 && response.statusCode < 400) {
        callback(response);
      }
    };

    var req = (parsedUrl.protocol === 'http:' ? http : https).request(requestOptions, requestCallback);
    // Add no-op error listener to prevent this from throwing
    req.on('error', function() {});
    req.write(dataString);
    req.end();
    return req;
  }
function ( eventObj , callback ) { // Non-POST requests not supported if ( eventObj . httpVerb !== 'POST' ) { return ; } var parsedUrl = url . parse ( eventObj . url ) ; var path = parsedUrl . path ; if ( parsedUrl . query ) { path += '?' + parsedUrl . query ; } var dataString = JSON . stringify ( eventObj . params ) ; var requestOptions = { host : parsedUrl . host , path : parsedUrl . path , method : 'POST' , headers : { 'content-type' : 'application/json' , 'content-length' : dataString . length . toString ( ) , } } ; var requestCallback = function ( response ) { if ( response && response . statusCode && response . statusCode >= 200 && response . statusCode < 400 ) { callback ( response ) ; } } ; var req = ( parsedUrl . protocol === 'http:' ? http : https ) . request ( requestOptions , requestCallback ) ; // Add no-op error listener to prevent this from throwing req . on ( 'error' , function ( ) { } ) ; req . write ( dataString ) ; req . end ( ) ; return req ; }
Dispatch an HTTP request to the given url and the specified options
@param {Object}  eventObj          Event object containing
@param {string}  eventObj.url      the url to make the request to
@param {Object}  eventObj.params   parameters to pass to the request (i.e. in the POST body)
@param {string}  eventObj.httpVerb the HTTP request method type. only POST is supported.
@param {function} callback         callback to execute
@return {ClientRequest|undefined}          ClientRequest object which made the request, or undefined if no request was made (error)
Dispatch an HTTP request to the given url and the specified options