<commit_before>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

/**
 * request.js
 *
 * requirements:
 *	 tools.js
 *
 */

/**
 */

/**
 * Implements a cross browser HTTPrequest-FIFO-queue as `singleton module'
 */
var requestQueue = function()
{
  var self = this;
  var queue = new Array();		//!< queue of waiting requests
  var xmlHttp;
  var spinner = null;

  if ( typeof XMLHttpRequest != 'undefined' )
  {
    xmlHttp = new XMLHttpRequest();
  }
  else
  {
    try { xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" ); }
    catch( e )
    {
      try { xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" ); }
      catch( e ){ xmlHttp = null; }
    }
  }

  var encodeArray = function( a, p )
  {
    var q = "";
    for ( var i = 0; i < a.length; ++i )
    {
      var r = p + "[" + i + "]";
      
      switch ( typeof a[ i ] )
      {
      case "undefined":
        break;
      case "function":
      case "object":
        if ( a[ i ].constructor == Array && a[ i ].length > 0 )
          q += encodeArray( a[ i ], r ) + "&";
        else
          q += encodeObject( a[ i ], r ) + "&";
        break;
      default:
        q += r + "=" + encodeURIComponent( a[ i ] ) + "&";
        break;
      }
    }
    q = q.replace( /\&$/, "" );
    
    return q;
  }

  var encodeObject = function( o, p )
  {
    var q = "";
    for ( var k in o )
    {
      var r;
      if ( p )
        r = p + "[" + k + "]";
      else
        r = k;
      
      switch ( typeof o[ k ] )
      {
      case "undefined":
        break;
      case "function":
      case "object":
        if ( o[ k ].constructor == Array && o[ k ].length > 0 )
          q += encodeArray( o[ k ], r ) + "&";
        else
          q += encodeObject( o[ k ], r ) + "&";
        break;
      default:
        q += r + "=" + encodeURIComponent( o[ k ] ) + "&";
        break;
      }
    }
    q = q.replace( /\&$/, "" );
    
    return q;
  }

  var showSpinner = function()
  {
    if ( !spinner )
      spinner = document.getElementById( "spinner" );
    if ( spinner )
      spinner.style.display = "block";
  }

  var hideSpinner = function()
  {
    if ( !spinner )
      spinner = document.getElementById( "spinner" );
    if ( spinner )
      spinner.style.display = "none";
  }

  var send = function()
  {
    showSpinner();
    xmlHttp.open(
      queue[ 0 ].method,
      queue[ 0 ].request,
      true );
    xmlHttp.setRequestHeader( "X-Requested-With", "XMLHttpRequest");
    if ( queue[ 0 ].method == "POST" )
    {
      xmlHttp.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
      // xmlHttp.setRequestHeader( "Content-length", queue[ 0 ].data.length );
      // xmlHttp.setRequestHeader( "Connection", "close" );
    }
    xmlHttp.onreadystatechange = callback;
    xmlHttp.send( queue[ 0 ].data );
    
    return;
  }<commit_msg>Add X-Requested-With header for request send with request queue<commit_after>/* -*- mode: espresso; espresso-indent-level: 2; indent-tabs-mode: nil -*- */
/* vim: set softtabstop=2 shiftwidth=2 tabstop=2 expandtab: */

/**
 * request.js
 *
 * requirements:
 *	 tools.js
 *
 */

/**
 */

/**
 * Implements a cross browser HTTPrequest-FIFO-queue as `singleton module'
 */
var requestQueue = function()
{
  var self = this;
  var queue = new Array();		//!< queue of waiting requests
  var xmlHttp;
  var spinner = null;

  if ( typeof XMLHttpRequest != 'undefined' )
  {
    xmlHttp = new XMLHttpRequest();
  }
  else
  {
    try { xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" ); }
    catch( e )
    {
      try { xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" ); }
      catch( e ){ xmlHttp = null; }
    }
  }

  var encodeArray = function( a, p )
  {
    var q = "";
    for ( var i = 0; i < a.length; ++i )
    {
      var r = p + "[" + i + "]";
      
      switch ( typeof a[ i ] )
      {
      case "undefined":
        break;
      case "function":
      case "object":
        if ( a[ i ].constructor == Array && a[ i ].length > 0 )
          q += encodeArray( a[ i ], r ) + "&";
        else
          q += encodeObject( a[ i ], r ) + "&";
        break;
      default:
        q += r + "=" + encodeURIComponent( a[ i ] ) + "&";
        break;
      }
    }
    q = q.replace( /\&$/, "" );
    
    return q;
  }

  var encodeObject = function( o, p )
  {
    var q = "";
    for ( var k in o )
    {
      var r;
      if ( p )
        r = p + "[" + k + "]";
      else
        r = k;
      
      switch ( typeof o[ k ] )
      {
      case "undefined":
        break;
      case "function":
      case "object":
        if ( o[ k ].constructor == Array && o[ k ].length > 0 )
          q += encodeArray( o[ k ], r ) + "&";
        else
          q += encodeObject( o[ k ], r ) + "&";
        break;
      default:
        q += r + "=" + encodeURIComponent( o[ k ] ) + "&";
        break;
      }
    }
    q = q.replace( /\&$/, "" );
    
    return q;
  }

  var showSpinner = function()
  {
    if ( !spinner )
      spinner = document.getElementById( "spinner" );
    if ( spinner )
      spinner.style.display = "block";
  }

  var hideSpinner = function()
  {
    if ( !spinner )
      spinner = document.getElementById( "spinner" );
    if ( spinner )
      spinner.style.display = "none";
  }

  var send = function()
  {
    showSpinner();
    xmlHttp.open(
      queue[ 0 ].method,
      queue[ 0 ].request,
      true );
    xmlHttp.setRequestHeader( "X-Requested-With", "XMLHttpRequest");
    if ( queue[ 0 ].method == "POST" )
    {
      xmlHttp.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
      // xmlHttp.setRequestHeader( "Content-length", queue[ 0 ].data.length );
      // xmlHttp.setRequestHeader( "Connection", "close" );
    }
    xmlHttp.setRequestHeader( "X-Requested-With", "XMLHttpRequest" );
    xmlHttp.onreadystatechange = callback;
    xmlHttp.send( queue[ 0 ].data );
    
    return;
  }
{'fraction_non_alphanumeric': 0.16538974017321786, 'fraction_numerical': 0.0043304463690872754, 'mean_word_length': 1.8113295880149813, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 27}, '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': '6590932', 'n_tokens_mistral': 2093, 'n_tokens_neox': 2061, 'n_words': 521}