<commit_before>"use strict";

var http = require("http"),
    when = require("when");

/**
 * Configures and starts the http request so it can be understood by the phantomjs process.
 *
 * @private
 * @param {Object} options
 * @returns {Promise}
 */
function request(options) {
    return when.promise(function (resolve, reject) {
        var req;

        options.method = options.method || "POST";
        options.host = options.host || "localhost";
        options.headers = {
            "Content-Length": options.body.length,
            "Content-Type":   "application/json"
        };

        req = http.request(options, function onResponse(response) {
            var body = "";

            response.setEncoding("utf8");
            response.on("data", function (chunk) {
                body += chunk;
            });
            response.on("error", reject);
            response.on("end", function () {
                response.body = body;
                resolve(response);
            });
        });
        req.on("error", reject);
        req.end(options.body);
    });
}

module.exports = request;<commit_msg>Fixed wrong content length when request body contains non-ascii characters<commit_after>"use strict";

var http = require("http"),
    when = require("when");

/**
 * Configures and starts the http request so it can be understood by the phantomjs process.
 *
 * @private
 * @param {Object} options
 * @returns {Promise}
 */
function request(options) {
    return when.promise(function (resolve, reject) {
        var req;

        options.method = options.method || "POST";
        options.host = options.host || "localhost";
        options.headers = {
            "Content-Length": Buffer.byteLength(options.body),
            "Content-Type":   "application/json"
        };

        req = http.request(options, function onResponse(response) {
            var body = "";

            response.setEncoding("utf8");
            response.on("data", function (chunk) {
                body += chunk;
            });
            response.on("error", reject);
            response.on("end", function () {
                response.body = body;
                resolve(response);
            });
        });
        req.on("error", reject);
        req.end(options.body);
    });
}

module.exports = request;
{'fraction_non_alphanumeric': 0.13685113685113684, 'fraction_numerical': 0.000858000858000858, 'mean_word_length': 2.0168175937904267, 'pattern_counts': {'":': 4, '<': 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': '7098983', 'n_tokens_mistral': 616, 'n_tokens_neox': 597, 'n_words': 150}