<commit_before><!--
  Copyright JS Foundation and other contributors, http://js.foundation

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<script type="text/x-red" data-template-name="http request">
    <div class="form-row">
        <label for="node-input-method"><i class="fa fa-tasks"></i> <span data-i18n="httpin.label.method"></span></label>
        <select type="text" id="node-input-method" style="width:70%;">
        <option value="GET">GET</option>
        <option value="POST">POST</option>
        <option value="PUT">PUT</option>
        <option value="DELETE">DELETE</option>
        <option value="use" data-i18n="httpin.setby"></option>
        </select>
    </div>

    <div class="form-row">
        <label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
        <input id="node-input-url" type="text" placeholder="http://">
    </div>

    <div class="form-row node-input-paytoqs-row">
        <input type="checkbox" id="node-input-paytoqs" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-paytoqs" style="width: auto" data-i18n="httpin.label.paytoqs"></label>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
        <div id="node-row-tls" class="hide">
            <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-tls"><span data-i18n="httpin.tls-config"></span></label><input type="text" style="width: 300px" id="node-input-tls">
        </div>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-useAuth" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-useAuth" style="width: 70%;"><span data-i18n="httpin.basicauth"></span></label>
        <div style="margin-left: 20px" class="node-input-useAuth-row hide">
            <div class="form-row">
                <label for="node-input-authType"><i class="fa fa-user-secret "></i> <span data-i18n="httpin.label.authType"></span></label>
                <select type="text" id="node-input-authType" style="width:70%;">
                    <option value="basic"  data-i18n="httpin.basic"></option>
                    <option value="digest" data-i18n="httpin.digest"></option>
                    <option value="bearer" data-i18n="httpin.bearer"></option>
                </select>
            </div>
            <div class="form-row node-input-basic-row">
                <label for="node-input-user"><i class="fa fa-user"></i> <span data-i18n="common.label.username"></span></label>
                <input type="text" id="node-input-user">
            </div>
            <div class="form-row">
                <label for="node-input-password"> <i class="fa fa-lock"></i> <span data-i18n="common.label.password" id="node-span-password"></span><span data-i18n="httpin.label.bearerToken" id="node-span-token" style="display:none"></span></label>
                <input type="password" id="node-input-password">
            </div>
        </div>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-useProxy" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-useProxy" style="width: auto;"><span data-i18n="httpin.use-proxy"></span></label>
        <div id="node-input-useProxy-row" class="hide">
            <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-proxy"><i class="fa fa-globe"></i> <span data-i18n="httpin.proxy-config"></span></label><input type="text" style="width: 270px" id="node-input-proxy">
        </div>
    </div>

    <div class="form-row">
        <label for="node-input-ret"><i class="fa fa-arrow-left"></i> <span data-i18n="httpin.label.return"></span></label>
        <select type="text" id="node-input-ret" style="width:70%;">
        <option value="txt" data-i18n="httpin.utf8"></option>
        <option value="bin" data-i18n="httpin.binary"></option>
        <option value="obj" data-i18n="httpin.json"></option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
    </div>
    <div class="form-tips" id="tip-json" hidden><span data-i18n="httpin.tip.req"></span></div>
</script>

<script type="text/javascript">
    RED.nodes.registerType('http request',{
        category: 'function',
        color:"rgb(231, 231, 174)",
        defaults: {
            name: {value:""},
            method:{value:"GET"},
            ret: {value:"txt"},
            paytoqs: {value: false},
            url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
            tls: {type:"tls-config",required: false},
            proxy: {type:"http proxy",required: false},
            authType: {value: "basic"}
        },
        credentials: {
            user: {type:"text"},
            password: {type: "password"}
        },
        inputs:1,
        outputs:1,
        outputLabels: function(i) {
            return ({
                txt: this._("httpin.label.utf8String"),
                bin: this._("httpin.label.binaryBuffer"),
                obj: this._("httpin.label.jsonObject")
            }[this.ret]);
        },
        icon: "white-globe.png",
        label: function() {
            return this.name||this._("httpin.httpreq");
        },
        labelStyle: function() {
            return this.name?"node_label_italic":"";
        },
        oneditprepare: function() {
            $("#node-input-useAuth").change(function() {
                if ($(this).is(":checked")) {
                    $(".node-input-useAuth-row").show();
                    // Nodes (< version 0.20.x) with credentials but without authentication type, need type 'basic'
                    if (!$('#node-input-authType').val()) {
                        $('#node-input-authType').val('basic');
                    }
                } else {
                    $(".node-input-useAuth-row").hide();
                    $('#node-input-authType').val('');
                    $('#node-input-user').val('');
                    $('#node-input-password').val('');
                }
            });
            $("#node-input-authType").change(function() {
                if ($(this).val() == "basic" || $(this).val() == "digest") {
                    $(".node-input-basic-row").show();
                    $('#node-span-password').show();
                    $('#node-span-token').hide();
                } else if ($(this).val() == "bearer") {
                    $(".node-input-basic-row").hide();
                    $('#node-span-password').hide();
                    $('#node-span-token').show();
                    $('#node-input-user').val('');
                }
            });
            $("#node-input-method").change(function() {
                if ($(this).val() == "GET") {
                    $(".node-input-paytoqs-row").show();
                } else {
                    $(".node-input-paytoqs-row").hide();
                }
            });
            if (this.credentials.user || this.credentials.has_password) {
                $('#node-input-useAuth').prop('checked', true);
            } else {
                $('#node-input-useAuth').prop('checked', false);
            }
            $("#node-input-useAuth").change();

            function updateTLSOptions() {
                if ($("#node-input-usetls").is(':checked')) {
                    $("#node-row-tls").show();
                } else {
                    $("#node-row-tls").hide();
                }<commit_msg>Clear HTTP Request node authType when auth disabled Fixes #2215<commit_after><!--
  Copyright JS Foundation and other contributors, http://js.foundation

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<script type="text/x-red" data-template-name="http request">
    <div class="form-row">
        <label for="node-input-method"><i class="fa fa-tasks"></i> <span data-i18n="httpin.label.method"></span></label>
        <select type="text" id="node-input-method" style="width:70%;">
        <option value="GET">GET</option>
        <option value="POST">POST</option>
        <option value="PUT">PUT</option>
        <option value="DELETE">DELETE</option>
        <option value="use" data-i18n="httpin.setby"></option>
        </select>
    </div>

    <div class="form-row">
        <label for="node-input-url"><i class="fa fa-globe"></i> <span data-i18n="httpin.label.url"></span></label>
        <input id="node-input-url" type="text" placeholder="http://">
    </div>

    <div class="form-row node-input-paytoqs-row">
        <input type="checkbox" id="node-input-paytoqs" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-paytoqs" style="width: auto" data-i18n="httpin.label.paytoqs"></label>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
        <div id="node-row-tls" class="hide">
            <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-tls"><span data-i18n="httpin.tls-config"></span></label><input type="text" style="width: 300px" id="node-input-tls">
        </div>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-useAuth" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-useAuth" style="width: 70%;"><span data-i18n="httpin.basicauth"></span></label>
        <div style="margin-left: 20px" class="node-input-useAuth-row hide">
            <div class="form-row">
                <label for="node-input-authType-select"><i class="fa fa-user-secret "></i> <span data-i18n="httpin.label.authType"></span></label>
                <select type="text" id="node-input-authType-select" style="width:70%;">
                    <option value="basic"  data-i18n="httpin.basic"></option>
                    <option value="digest" data-i18n="httpin.digest"></option>
                    <option value="bearer" data-i18n="httpin.bearer"></option>
                </select>
                <input type="hidden" id="node-input-authType">
            </div>
            <div class="form-row node-input-basic-row">
                <label for="node-input-user"><i class="fa fa-user"></i> <span data-i18n="common.label.username"></span></label>
                <input type="text" id="node-input-user">
            </div>
            <div class="form-row">
                <label for="node-input-password"> <i class="fa fa-lock"></i> <span data-i18n="common.label.password" id="node-span-password"></span><span data-i18n="httpin.label.bearerToken" id="node-span-token" style="display:none"></span></label>
                <input type="password" id="node-input-password">
            </div>
        </div>
    </div>

    <div class="form-row">
        <input type="checkbox" id="node-input-useProxy" style="display: inline-block; width: auto; vertical-align: top;">
        <label for="node-input-useProxy" style="width: auto;"><span data-i18n="httpin.use-proxy"></span></label>
        <div id="node-input-useProxy-row" class="hide">
            <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-proxy"><i class="fa fa-globe"></i> <span data-i18n="httpin.proxy-config"></span></label><input type="text" style="width: 270px" id="node-input-proxy">
        </div>
    </div>

    <div class="form-row">
        <label for="node-input-ret"><i class="fa fa-arrow-left"></i> <span data-i18n="httpin.label.return"></span></label>
        <select type="text" id="node-input-ret" style="width:70%;">
        <option value="txt" data-i18n="httpin.utf8"></option>
        <option value="bin" data-i18n="httpin.binary"></option>
        <option value="obj" data-i18n="httpin.json"></option>
        </select>
    </div>
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
        <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
    </div>
    <div class="form-tips" id="tip-json" hidden><span data-i18n="httpin.tip.req"></span></div>
</script>

<script type="text/javascript">
    RED.nodes.registerType('http request',{
        category: 'function',
        color:"rgb(231, 231, 174)",
        defaults: {
            name: {value:""},
            method:{value:"GET"},
            ret: {value:"txt"},
            paytoqs: {value: false},
            url:{value:"",validate:function(v) { return (v.trim().length === 0) || (v.indexOf("://") === -1) || (v.trim().indexOf("http") === 0)} },
            tls: {type:"tls-config",required: false},
            proxy: {type:"http proxy",required: false},
            authType: {value: ""}
        },
        credentials: {
            user: {type:"text"},
            password: {type: "password"}
        },
        inputs:1,
        outputs:1,
        outputLabels: function(i) {
            return ({
                txt: this._("httpin.label.utf8String"),
                bin: this._("httpin.label.binaryBuffer"),
                obj: this._("httpin.label.jsonObject")
            }[this.ret]);
        },
        icon: "white-globe.png",
        label: function() {
            return this.name||this._("httpin.httpreq");
        },
        labelStyle: function() {
            return this.name?"node_label_italic":"";
        },
        oneditprepare: function() {
            $("#node-input-useAuth").change(function() {
                if ($(this).is(":checked")) {
                    $(".node-input-useAuth-row").show();
                    // Nodes (< version 0.20.x) with credentials but without authentication type, need type 'basic'
                    if (!$('#node-input-authType').val()) {
                        $("#node-input-authType-select").val('basic').trigger("change");
                    }
                } else {
                    $(".node-input-useAuth-row").hide();
                    $('#node-input-authType').val('');
                    $('#node-input-user').val('');
                    $('#node-input-password').val('');
                }
            });
            $("#node-input-authType-select").change(function() {
                var val = $(this).val();
                $("#node-input-authType").val(val);
                if (val === "basic" || val === "digest") {
                    $(".node-input-basic-row").show();
                    $('#node-span-password').show();
                    $('#node-span-token').hide();
                } else if (val === "bearer") {
                    $(".node-input-basic-row").hide();
                    $('#node-span-password').hide();
                    $('#node-span-token').show();
                    $('#node-input-user').val('');
                }
            });
            $("#node-input-method").change(function() {
                if ($(this).val() == "GET") {
                    $(".node-input-paytoqs-row").show();
                } else {
                    $(".node-input-paytoqs-row").hide();
                }
            });
            if (this.authType) {
                $('#node-input-useAuth').prop('checked', true);
                $("#node-input-authType-select").val(this.authType);
            } else {
                $('#node-input-useAuth').prop('checked', false);
            }
            $("#node-input-useAuth").change();

            function updateTLSOptions() {
                if ($("#node-input-usetls").is(':checked')) {
                    $("#node-row-tls").show();
                } else {
                    $("#node-row-tls").hide();
                }
{'fraction_non_alphanumeric': 0.1933650388586011, 'fraction_numerical': 0.011019603294281406, 'mean_word_length': 2.211585025144347, 'pattern_counts': {'":': 6, '<': 286, '<?xml version=': 0, '>': 284, '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': '5527222', 'n_tokens_mistral': 5274, 'n_tokens_neox': 5056, 'n_words': 947}