<commit_before>/*
 * resteasy.js - Interactivity for the REST Easy addon
 * Copyright 2013 - <NAME>
 */

function RestEasy() {

    // Initialize the method dropdown
    var request_method = new Dropdown($('#request-method'), ['GET', 'POST', 'HEAD']);

    // Initialize the MapInput controls
    var request_parameters = new MapInput($('#request-parameters-control'));
    var request_headers    = new MapInput($('#request-headers-control'));

    // Toggles progress display
    function showProgress(show) {

        if(show) {
            $('#response-tabs').hide();
            $('#response-progress').show();
        } else {
            $('#response-progress').hide();
            $('#response-tabs').show();
        }
    }

    // Issues the request
    $('#send').click(function() {

        // Ignore an empty request
        if(!$('#url').val().trim().length)
            return;

        var request = new XMLHttpRequest();
        request.open(request_method.get(),
                     $('#url').val(),
                     true,
                     $('#request-username').val(),
                     $('#request-password').val());

        var headers = request_headers.get();
        for(var name in headers)
            request.setRequestHeader(name, headers[name]);

        if(request_method.get() == 'POST')
            request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

        request.onreadystatechange = function() {

            if(request.readyState == 4) {

                var response = new Response(request);
                response.appendHeaders($('#response-headers'));
                response.appendRaw($('#response-raw'));
                response.appendPreview($('#response-preview'));

                showProgress(false);
            }
        };

        // URL-encode the POST data
        var parameters = request_parameters.get(),
            param_str = [];
        for(var param in parameters)
            param_str.push(encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]));
        param_str = param_str.join('&');

        showProgress(true);
        $('#response-tabs .tab-pane').empty();

        request.send(param_str);
    });

    // Ensure that the panels are sized correctly when the page is resized
    $(window).resize(function() {
<commit_msg>Added ability to set nearly any HTTP header now, including 'User-Agent' (closes #12).<commit_after>/*
 * resteasy.js - Interactivity for the REST Easy addon
 * Copyright 2013 - <NAME>
 */

function RestEasy() {

    // Initialize the method dropdown
    var request_method = new Dropdown($('#request-method'), ['GET', 'POST', 'HEAD']);

    // Initialize the MapInput controls
    var request_parameters = new MapInput($('#request-parameters-control'));
    var request_headers    = new MapInput($('#request-headers-control'));

    // Toggles progress display
    function showProgress(show) {

        if(show) {
            $('#response-tabs').hide();
            $('#response-progress').show();
        } else {
            $('#response-progress').hide();
            $('#response-tabs').show();
        }
    }

    // Issues the request
    $('#send').click(function() {

        // Ignore an empty request
        if(!$('#url').val().trim().length)
            return;

        var request = new XMLHttpRequest();
        request.open(request_method.get(),
                     $('#url').val(),
                     true,
                     $('#request-username').val(),
                     $('#request-password').val());

        // We must obtain an nsIHttpChannel interface in order to set certain headers
        var channel = request.channel.QueryInterface(Components.interfaces.nsIHttpChannel);

        var headers = request_headers.get();
        for(var name in headers)
            channel.setRequestHeader(name, headers[name], false);

        if(request_method.get() == 'POST')
            channel.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

        request.onreadystatechange = function() {

            if(request.readyState == 4) {

                var response = new Response(request);
                response.appendHeaders($('#response-headers'));
                response.appendRaw($('#response-raw'));
                response.appendPreview($('#response-preview'));

                showProgress(false);
            }
        };

        // URL-encode the POST data
        var parameters = request_parameters.get(),
            param_str = [];
        for(var param in parameters)
            param_str.push(encodeURIComponent(param) + '=' + encodeURIComponent(parameters[param]));
        param_str = param_str.join('&');

        showProgress(true);
        $('#response-tabs .tab-pane').empty();

        request.send(param_str);
    });

    // Ensure that the panels are sized correctly when the page is resized
    $(window).resize(function() {

{'fraction_non_alphanumeric': 0.14893188230552196, 'fraction_numerical': 0.0024183796856106408, 'mean_word_length': 2.1491116751269037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '4973528', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1239, 'n_words': 276}