<commit_before>var spawn = require('cross-spawn'),
  path = require('path'),
  fs = require('fs'),
  async = require('async'),
  MobProxy = require('browsermob-proxy-api');

function Proxy(config) {
  this.port = config.port;
  if (config.basicAuth) {
    this.basicAuth = config.basicAuth;
  }
  if (config.headers) {
    this.headers = config.headers;
  }
  if (config.limit) {
    this.limit = config.limit;
  }

}

Proxy.prototype.start = function(cb) {
  // start the browsermob proxy
  this.java = spawn('java', ['-jar', path.join(__dirname, 'bmpwrapper-0.0.1-SNAPSHOT-full.jar'), '-port', '9093']);


  this.java.stdout.on('data', function(data) {
    console.log(data);
  });
  this.java.stderr.on('data', function(data) {
    console.log('e:' + data);
  });

  var self = this;

  setTimeout(function() {

    self.proxy = new MobProxy({
      'host': 'localhost',
      'port': '9093'
    });


    self.proxy.startPort(this.port, function(err, data) {
      async.series([

          function(callback) {
            self.proxy.createHAR(self.port, {
              'initialPageRef': 'foo',
              'captureHeaders': true
            }, callback);
          }
          /*,
          function(callback) {
            if (self.headers) {
              self.proxy.setHeaders(self.port, JSON.stringify(self.headers), callback);
            } else {
              callback();
            }
          },
          function(callback) {
            if (self.basicAuth) {
              self.proxy.setAuthentication(443, domain, json, callback);
            }
          },
          function(callback) {
            if (self.limit) {
              self.proxy.setLimit(self.port, self.limit, callback);
            }
          }*/
        ],
        // optional callback
        function(err, results) {
          cb();
        });
    });
  }, 2000);
};

Proxy.prototype.newPage = function(name) {
  this.proxy.startNewPage(this.port, name, function() {});
};

Proxy.prototype.stop = function(cb) {
  // close the proxy
  var self = this;
  this.proxy.stopPort(this.port, function() {

    try {
      self.java.kill('SIGHUP');
    } catch (error) {
      console.log(error);
    }
    cb();
  });<commit_msg>call the callbacks<commit_after>var spawn = require('cross-spawn'),
  path = require('path'),
  fs = require('fs'),
  async = require('async'),
  MobProxy = require('browsermob-proxy-api');

function Proxy(config) {
  this.port = config.port;
  if (config.basicAuth) {
    this.basicAuth = config.basicAuth;
  }
  if (config.headers) {
    this.headers = config.headers;
  }
  if (config.limit) {
    this.limit = config.limit;
  }

}

Proxy.prototype.start = function(cb) {
  // start the browsermob proxy
  this.java = spawn('java', ['-jar', path.join(__dirname, 'bmpwrapper-0.0.1-SNAPSHOT-full.jar'), '-port', '9093']);

  /*
  this.java.stdout.on('data', function(data) {
    console.log(data);
  });
  this.java.stderr.on('data', function(data) {
    console.log('e:' + data);
  });
  */

  var self = this;
  console.log('Waiting on the proxy to start ...');
  setTimeout(function() {
    self.proxy = new MobProxy({
      'host': 'localhost',
      'port': '9093'
    });


    self.proxy.startPort(self.port, function(err, data) {
      async.series([

          function(callback) {
            self.proxy.createHAR(self.port, {
              'initialPageRef': 'foo',
              'captureHeaders': true
            }, callback);
          },
          function(callback) {
            if (self.headers) {
              self.proxy.setHeaders(self.port, JSON.stringify(self.headers), callback);
            } else {
              callback();
            }
          },
          function(callback) {
            if (self.basicAuth) {
              self.proxy.setAuthentication(443, domain, json, callback);
            } else {
              callback();
            }
          },
          function(callback) {
            if (self.limit) {
              self.proxy.setLimit(self.port, self.limit, callback);
            } else {
              callback();
            }
          }
        ],
        // optional callback
        function(err, results) {
          cb();
        });
    });
  }, 2000);
};

Proxy.prototype.newPage = function(name) {
  this.proxy.startNewPage(this.port, name, function() {});
};

Proxy.prototype.stop = function(cb) {
  // close the proxy
  var self = this;
  this.proxy.stopPort(this.port, function() {

    try {
      self.java.kill('SIGHUP');
    } catch (error) {
      console.log(error);
    }
    cb();
  });
{'fraction_non_alphanumeric': 0.1619672131147541, 'fraction_numerical': 0.007868852459016393, 'mean_word_length': 1.9791666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5237802', 'n_tokens_mistral': 1447, 'n_tokens_neox': 1419, 'n_words': 246}