<commit_before>/*
HTTPRequest v0.0.3
https://github.com/keverw/HTTPRequest
*/
var HTTPRequest = {
    //Public
    post: function (url, data, callback, options)
    {
        var parameters = {
            METHOD: 'POST',
            data: data
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback, options);
    },
    put: function (url, data, callback, options)
    {
        var parameters = {
            METHOD: 'PUT',
            data: data
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback, options);
    },
    get: function (url, callback, options)
    {
        var parameters = {
            METHOD: 'GET'
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback);
    },
    del: function (url, callback, options)
    {
        var parameters = {
            METHOD: 'DELETE'
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback);
    },
    request: function (url, parameters, callback)
    {
        parameters = this._key2lower(parameters);

        if (typeof parameters.method == 'undefined')
        {
            parameters.method = 'GET';
        }

        //CONTENT TYPE
        if (typeof parameters.datatype != 'undefined')
        {
            parameters.datatype = parameters.datatype.toLowerCase();
            if (parameters.datatype != 'json')
            {
                console.log('Invalid datatype option');
            }
        }
        else
        {
            parameters.datatype = null;
        }

        //data
        if (typeof parameters.data != 'undefined')
        {
            parameters.data = this._objToQuery(parameters.data);
        }

        if (typeof parameters.query != 'undefined')
        {
            parameters.query = this._objToQuery(parameters.query);
            if (url.indexOf('?') !== -1)
            { //Has ?
                url += '&' + parameters.query;
            }
            else //add ?
            {
                url += '?' + parameters.query;
            }
        }

        //do XHR
        var xhr = this._getXHR();
        if (xhr == null) //NO XHR :(
        {
            callback(0, {}, null); //return an error code zero
        }
        else
        {
            var that = this;
            xhr.onreadystatechange = function ()
            {
                if (xhr.readyState == 4) //HTTP results!
                {
                    if (parameters.datatype == 'json') //json
                    {
                        console.log(that.parseJSON(xhr.responseText)); //temp
                        callback(xhr.status, that._headersToHeaders(xhr.getAllResponseHeaders()), xhr.responseText);
                    }
                    else //other
                    {
                        callback(xhr.status, that._headersToHeaders(xhr.getAllResponseHeaders()), xhr.responseText);
                    }
                }
            }
            xhr.open(parameters.method, url, true);
            if (typeof exports == 'object' && exports)
            {
                if (typeof parameters.useragent != 'undefined')
                {
                	xhr.disableHeaderCheck(true); //Disable header check
                    xhr.setRequestHeader('User-Agent', parameters.useragent);
                }
            }

            if (parameters.method == 'POST')
            {
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                if (typeof parameters.data != 'undefined')
                {
                    // xhr.setRequestHeader("Content-length", parameters.data.length);
                }
                //xhr.setRequestHeader("Connection", "close");
            }

            if (parameters.method == 'POST' || parameters.method == 'PUT')
            {
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                if (typeof parameters.data != 'undefined')
                {
                    // xhr.setRequestHeader("Content-length", parameters.data.length);
                }
                //xhr.setRequestHeader("Connection", "close");<commit_msg>sends custom headers to server<commit_after>/*
HTTPRequest v0.0.3
https://github.com/keverw/HTTPRequest
*/
var HTTPRequest = {
    //Public
    post: function (url, data, callback, options)
    {
        var parameters = {
            METHOD: 'POST',
            data: data
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback, options);
    },
    put: function (url, data, callback, options)
    {
        var parameters = {
            METHOD: 'PUT',
            data: data
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback, options);
    },
    get: function (url, callback, options)
    {
        var parameters = {
            METHOD: 'GET'
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback);
    },
    del: function (url, callback, options)
    {
        var parameters = {
            METHOD: 'DELETE'
        };

        var request_parms = this._mergeobjs(options, parameters);

        this.request(url, request_parms, callback);
    },
    request: function (url, parameters, callback)
    {
        parameters = this._key2lower(parameters);

        if (typeof parameters.method == 'undefined')
        {
            parameters.method = 'GET';
        }

        //CONTENT TYPE
        if (typeof parameters.datatype != 'undefined')
        {
            parameters.datatype = parameters.datatype.toLowerCase();
            if (parameters.datatype != 'json')
            {
                console.log('Invalid datatype option');
            }
        }
        else
        {
            parameters.datatype = null;
        }

        //data
        if (typeof parameters.data != 'undefined')
        {
            parameters.data = this._objToQuery(parameters.data);
        }

        if (typeof parameters.query != 'undefined')
        {
            parameters.query = this._objToQuery(parameters.query);
            if (url.indexOf('?') !== -1)
            { //Has ?
                url += '&' + parameters.query;
            }
            else //add ?
            {
                url += '?' + parameters.query;
            }
        }

        //do XHR
        var xhr = this._getXHR();
        if (xhr == null) //NO XHR :(
        {
            callback(0, {}, null); //return an error code zero
        }
        else
        {
            var that = this;
            xhr.onreadystatechange = function ()
            {
                if (xhr.readyState == 4) //HTTP results!
                {
                    if (parameters.datatype == 'json') //json
                    {
                        console.log(that.parseJSON(xhr.responseText)); //temp
                        callback(xhr.status, that._headersToHeaders(xhr.getAllResponseHeaders()), xhr.responseText);
                    }
                    else //other
                    {
                        callback(xhr.status, that._headersToHeaders(xhr.getAllResponseHeaders()), xhr.responseText);
                    }
                }
            }
            xhr.open(parameters.method, url, true);
            if (typeof exports == 'object' && exports)
            {
            	xhr.disableHeaderCheck(true); //Disable header check
                if (typeof parameters.useragent != 'undefined')
                {	
                    xhr.setRequestHeader('User-Agent', parameters.useragent);
                }
                
                if (typeof parameters.headers == 'object')
                {
                	for (var key in parameters.headers)
           			{
           				xhr.setRequestHeader(key, parameters.headers[key]);
	                }
                }
            }

            if (parameters.method == 'POST')
            {
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                if (typeof parameters.data != 'undefined')
                {
                    // xhr.setRequestHeader("Content-length", parameters.data.length);
                }
                //xhr.setRequestHeader("Connection", "close");
            }

            if (parameters.method == 'POST' || parameters.method == 'PUT')
            {
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                if (typeof parameters.data != 'undefined')
                {
                    // xhr.setRequestHeader("Content-length", parameters.data.length);
                }
                //xhr.setRequestHeader("Connection", "close");
{'fraction_non_alphanumeric': 0.1181285256055746, 'fraction_numerical': 0.0015485012719831878, 'mean_word_length': 1.3719832109129066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '54316', 'n_tokens_mistral': 2378, 'n_tokens_neox': 2259, 'n_words': 454}