<commit_before>Kadira = {};
Kadira.options = __meteor_runtime_config__.kadira || {};
Kadira.options.errorDumpInterval = Kadira.options.errorDumpInterval || 1000*60;
Kadira.options.maxErrorsPerInterval = Kadira.options.maxErrorsPerInterval || 10;

if(Kadira.options.collectAllStacks === undefined) {
  Kadira.options.collectAllStacks = false;
}

Kadira.send = function (payload) {
  var endpoint = Kadira.options.endpoint + '/errors';
  var retryCount = 0;
  var retry = new Retry({
    minCount: 1,
    minTimeout: 0,
    baseTimeout: 1000*5,
    maxTimeout: 1000*60,
  });
  tryToSend();

  function tryToSend() {
    if(retryCount < 5) {
      retry.retryLater(retryCount++, function () {
        $.ajax({
          type: 'POST',
          url: endpoint,
          contentType: 'application/json',
          data: JSON.stringify(payload),
          error: tryToSend
        });
      });
    } else {
      console.warn('Error sending error traces to kadira server');
    }
  }
}

if(Kadira.options && Kadira.options.endpoint) {
  Kadira.syncedDate = new Ntp(Kadira.options.endpoint);
  Kadira.errors = new KadiraErrorModel({
    waitForNtpSyncInterval: 1000 * 5, // 5 secs
    intervalInMillis: 1000 * 60 * 1, // 1minutes
    maxErrorsPerInterval: 5
  });
  Kadira.connected = true;

  // ntp time sync uses jsonp which can block rendering the page
  // call ntp sync after the page is loaded and rendered
  Meteor.startup(function() {
    Kadira.syncedDate.sync();
  });
}

/**
 * IE8 and IE9 does not support CORS with the usual XMLHttpRequest object
 * If XDomainRequest exists, use it to send errors.
 * XDR can POST data to HTTPS endpoints only if current page uses HTTPS
 */
if (window.XDomainRequest) {
  $.ajaxTransport(function(s) {
    return {
      send: function (headers, callback) {
        var xdr = new XDomainRequest();
        var data = s.data || null;
        var url = matchPageProtocol(s.url);

        xdr.onload = function () {
          var headers = {'Content-Type': xdr.contentType};
          callback(200, 'OK', {text: xdr.responseText}, headers);
        }

        xdr.onerror = function () {
          callback(404);
        }

        xdr.open(s.type, url);
        xdr.send(data);
      }
    };
  });
}

function matchPageProtocol (endpoint) {
  var withoutProtocol = endpoint.substr(endpoint.indexOf(':'));
  return window.location.protocol + withoutProtocol;
}<commit_msg>Fix setting correct protocol for XDR<commit_after>Kadira = {};
Kadira.options = __meteor_runtime_config__.kadira || {};
Kadira.options.errorDumpInterval = Kadira.options.errorDumpInterval || 1000*60;
Kadira.options.maxErrorsPerInterval = Kadira.options.maxErrorsPerInterval || 10;

if(Kadira.options.collectAllStacks === undefined) {
  Kadira.options.collectAllStacks = false;
}

Kadira.send = function (payload) {
  var endpoint = Kadira.options.endpoint + '/errors';
  var retryCount = 0;
  var retry = new Retry({
    minCount: 1,
    minTimeout: 0,
    baseTimeout: 1000*5,
    maxTimeout: 1000*60,
  });
  tryToSend();

  function tryToSend() {
    if(retryCount < 5) {
      retry.retryLater(retryCount++, function () {
        $.ajax({
          type: 'POST',
          url: endpoint,
          contentType: 'application/json',
          data: JSON.stringify(payload),
          error: tryToSend
        });
      });
    } else {
      console.warn('Error sending error traces to kadira server');
    }
  }
}

if(Kadira.options && Kadira.options.endpoint) {
  Kadira.syncedDate = new Ntp(Kadira.options.endpoint);
  Kadira.errors = new KadiraErrorModel({
    waitForNtpSyncInterval: 1000 * 5, // 5 secs
    intervalInMillis: 1000 * 60 * 1, // 1minutes
    maxErrorsPerInterval: 5
  });
  Kadira.connected = true;

  // ntp time sync uses jsonp which can block rendering the page
  // call ntp sync after the page is loaded and rendered
  Meteor.startup(function() {
    Kadira.syncedDate.sync();
  });
}

/**
 * IE8 and IE9 does not support CORS with the usual XMLHttpRequest object
 * If XDomainRequest exists, use it to send errors.
 * XDR can POST data to HTTPS endpoints only if current page uses HTTPS
 */
if (window.XDomainRequest) {
  $.ajaxTransport(function(s) {
    return {
      send: function (headers, callback) {
        var xdr = new XDomainRequest();
        var data = s.data || null;
        var url = matchPageProtocol(s.url);

        xdr.onload = function () {
          var headers = {'Content-Type': xdr.contentType};
          callback(200, 'OK', {text: xdr.responseText}, headers);
        }

        xdr.onerror = function () {
          callback(404);
        }

        xdr.open(s.type, url);
        xdr.send(data);
      }
    };
  });
}

function matchPageProtocol (endpoint) {
  var withoutProtocol = endpoint.substr(endpoint.indexOf(':') + 1);
  return window.location.protocol + withoutProtocol;
}
{'fraction_non_alphanumeric': 0.12342880692355244, 'fraction_numerical': 0.019163404079950545, 'mean_word_length': 2.8523809523809525, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3668888', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1516, 'n_words': 374}