<commit_before>/**
 * Function: HttpServer
 *
 * The HttpServer object is used to create a very basic HTTP Server, used mainly
 * for assisting jaribu in verifying the functionality of it's http-suite.js
 *
 *      env.expected = { // struct of expected results for each http call
 *         test: {
 *            foo: "bar"
 *          }
 *      };
 *
 *      env.server = new this.HttpServer({
 *          port: 9991,
 *          uris: env.expected
 *      });
 *      this.assertAnd(env.server.run(), true);
 *
 * Parameters:
 *
 *   object conatining the properties:
 *       port - port to run on
 *
 *       uris - an object where the first set of properties are URIs the values
 *              attached to them are the data sets to return.
 *
 * Returns:
 *
 *   returns output from the function passed as parameter
 */
if (typeof define !== 'function') {
  var define = require('amdefine')(module);
}
define([], function (undefined) {

  var HttpServer = function (cfg) {
    if (typeof cfg.port === 'number') {
      this.port = cfg.port;
    }
    if (typeof cfg.uris === 'object') {
      this.uris = cfg.uris;
    }
  };

  HttpServer.prototype = {
    port: 9500,
    uris: {},
    http: undefined
  };

  HttpServer.prototype.run = function (callback) {
    var key;
    var express = requirejs('express');

    this.http = requirejs('http');
    var app = express();

    app.configure(function () {
      app.set('port', this.port);
      app.use(express.urlencoded());
      app.use(express.json());
      app.use(app.router);
    });

    var _this = this;
    for (key in this.uris) {
      app.get('/'+key, function (req, res) {
        res.send(_this.uris[key]);
      });
      app.post('/'+key, function (req, res) {
        _this.uris[key] = req.body;
        res.send('POST /'+key);
      });
      app.del('/'+key, function (req, res) {
        _this.uris[key] = req.body;
        res.send('DEL /'+key);
      });
      app.put('/'+key, function (req, res) {
        _this.uris[key] = req.body;
        res.send('PUT /'+key);
      });
    }

    app.get('/', function (req, res) {
      res.send('jaribu');
    });

    this.server = this.http.createServer(app);
    this.server.listen(this.port, '127.0.0.1', function () {
      console.log('listening at: ',_this.server.address());
      callback();
    });
  };<commit_msg>updated httpserver to use express 4<commit_after>/**
 * Function: HttpServer
 *
 * The HttpServer object is used to create a very basic HTTP Server, used mainly
 * for assisting jaribu in verifying the functionality of it's http-suite.js
 *
 *      env.expected = { // struct of expected results for each http call
 *         test: {
 *            foo: "bar"
 *          }
 *      };
 *
 *      env.server = new this.HttpServer({
 *          port: 9991,
 *          uris: env.expected
 *      });
 *      this.assertAnd(env.server.run(), true);
 *
 * Parameters:
 *
 *   object conatining the properties:
 *       port - port to run on
 *
 *       uris - an object where the first set of properties are URIs the values
 *              attached to them are the data sets to return.
 *
 * Returns:
 *
 *   returns output from the function passed as parameter
 */
if (typeof define !== 'function') {
  var define = require('amdefine')(module);
}
define([], function (undefined) {

  var HttpServer = function (cfg) {
    if (typeof cfg.port === 'number') {
      this.port = cfg.port;
    }
    if (typeof cfg.uris === 'object') {
      this.uris = cfg.uris;
    }
  };

  HttpServer.prototype = {
    port: 9500,
    uris: {},
    http: undefined
  };

  HttpServer.prototype.run = function (callback) {
    var key;
    var express    = requirejs('express');
    var bodyParser = requirejs('body-parser');

    this.http = requirejs('http');
    var app   = express();

    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(bodyParser.json());

    var _this = this;
    function __addRoutes(key) {
      app.get('/' + key, function (req, res) {
        console.log('GET CALLED ['+key+']: ');
        res.json(_this.uris[key]);
      });
      app.post('/' + key, function (req, res) {
        console.log('POST CALLED ['+key+']: ', req.body);
        _this.uris[key] = req.body;
        res.json('POST /' + key);
      });
      app.delete('/' + key, function (req, res) {
        _this.uris[key] = req.body;
        res.json('DEL /' + key);
      });
      app.put('/' + key, function (req, res) {
        _this.uris[key] = req.body;
        res.json('PUT /' + key);
      });
    }

    for (key in this.uris) {
      __addRoutes(key);
    }

    app.get('/', function (req, res) {
      res.json({ name: "jaribu" });
    });

    this.server = this.http.createServer(app);
    this.server.listen(this.port, '127.0.0.1', function () {
      console.log('listening at: ', _this.server.address());
      callback();
    });
  };
{'fraction_non_alphanumeric': 0.1615934627170582, 'fraction_numerical': 0.005924412665985699, 'mean_word_length': 2.181286549707602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1842318', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1561, 'n_words': 402}