<commit_before>/**
 * Created by park on 11/16/2015.
 * @see https://nodejs.org/api/http.html#http_http_request_options_callback
 * @see https://www.npmjs.com/package/http-post
 */
var http = require('http'),
    post = require('http-post');

var HttpClient = function() {
    var self = this,
        _host,
        _port,
        _baseURL;

    /**
     * REQUIRED -- set in environment.js
     * @param host
     * @param port
     */
    self.init = function(host, port) {
        _host = host;
        _port = port;
        _baseURL = "http://"+host;
        if (port !== 80) {
            _baseURL += ":"+port;
        }
        console.log('HttpClient '+host+" "+port);
    };

    /**
     *
     * @param path e.g. /tm/
     * @param queryJSON
     * @param callback
     */
    self.post = function(path, queryJSON, callback) {
        var content = JSON.stringify(queryJSON);
        var urx = _baseURL+path+content;
        var err,
            body='',
            result;
        var request = post(urx,{}, function hra(response) {
            console.log('STATUS: ' + response.statusCode);
            response.setEncoding('utf8');
            response.on('data', function(chunk){
                body += chunk;
            });

            response.on('end', function(){
                console.log("HTTP-POST "+body);
                result = JSON.parse(body);
                return callback(err, result);
            });

         }).on('error', function(e) {
            console.log('problem with request: ' + e.message);
            return callback(err, result);
        });
    };

    /**
     *
     * @param path e.g. /tm/
     * @param queryJSON
     * @param callback signature (err, rslt)
     */
    self.get = function(path, queryJSON, callback) {<commit_msg>Bug fix: add encodeURI to post<commit_after>/**
 * Created by park on 11/16/2015.
 * @see https://nodejs.org/api/http.html#http_http_request_options_callback
 * @see https://www.npmjs.com/package/http-post
 */
var http = require('http'),
    post = require('http-post');

var HttpClient = function() {
    var self = this,
        _host,
        _port,
        _baseURL;

    /**
     * REQUIRED -- set in environment.js
     * @param host
     * @param port
     */
    self.init = function(host, port) {
        _host = host;
        _port = port;
        _baseURL = "http://"+host;
        if (port !== 80) {
            _baseURL += ":"+port;
        }
        console.log('HttpClient '+host+" "+port);
    };

    /**
     *
     * @param path e.g. /tm/
     * @param queryJSON
     * @param callback
     */
    self.post = function(path, queryJSON, callback) {
        var content = encodeURI(JSON.stringify(queryJSON));
        var urx = _baseURL+path+content;
        var err,
            body='',
            result;
        var request = post(urx,{}, function hra(response) {
            console.log('STATUS: ' + response.statusCode);
            response.setEncoding('utf8');
            response.on('data', function(chunk){
                body += chunk;
            });

            response.on('end', function(){
                console.log("HTTP-POST "+body);
                result = JSON.parse(body);
                return callback(err, result);
            });

         }).on('error', function(e) {
            console.log('problem with request: ' + e.message);
            return callback(err, result);
        });
    };

    /**
     *
     * @param path e.g. /tm/
     * @param queryJSON
     * @param callback signature (err, rslt)
     */
    self.get = function(path, queryJSON, callback) {
{'fraction_non_alphanumeric': 0.15058236272878536, 'fraction_numerical': 0.006100942872989462, 'mean_word_length': 1.71203007518797, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '6941430', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1062, 'n_words': 237}