<commit_before><commit_msg>Added the Transport object.<commit_after>/*!
 *
 */
HTTPS = require('https');

module.exports = Transport = {};

/**
 * Do an HTTPS request.
 *
 * This performs a simple HTTPS request, and then
 * executes the callback, passing the response object into the
 * callback.
 *
 * @param {object} opts
 *   An object containing, at minimum, a parsed URL.
 *   To create a new opts, use URL.parse(url).
 * @param {string} body
 *   The body o fthe request.
 * @param {Function} fn
 *   A callback function. This receives an Error (on error), a Response,
 *   and (if present) the data as a string.
 */
Transport.doRequest = function(opts, body, fn) {

  // Define the request.
  var req = HTTPS.request(opts, function (response) {
    // We accept only 200.
    if (response.statusCode == 200) {
      var responseData = '';
      response.on('data', function (bytes) {
        responseData += bytes;
      });
      response.on('end', function() {
        fn(false, response, responseData);
      });
    }
    else {
      console.log("FAILED with HTTP status code %d", response.statusCode);
      var e = new Error('HTTP Error ' + response.statusCode);
      e.statusCode = response.statusCode;
      fn(e);
    }
  });

  // FIXME: Use better error handling.
  req.on('error', function (e) {
    console.log('FAILED outside of HTTP: ' + e.message);
    var err = new Error('Non-HTTP error: ' + e.message);
    err.statusCode = 0;
    fn(err);
  });

  // Write the body and trigger the request.
  req.write(body);
  req.end();

}


{'fraction_non_alphanumeric': 0.13881748071979436, 'fraction_numerical': 0.004498714652956298, 'mean_word_length': 2.7427884615384617, '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': '6092017', 'n_tokens_mistral': 481, 'n_tokens_neox': 471, 'n_words': 157}