<commit_before>var _ = require('lodash'),
    async = require('async'),
    requests = require('request'),
    dns = require('dns'),
    Socket = require('net').Socket,

    LOCAL_IPV6 = '::1',
    LOCAL_IPV4 = '127.0.0.1',
    LOCALHOST = 'localhost',
    SOCKET_TIMEOUT = 500,

    /**
     * Tries to make a TCP connection to the given host and port. If successful, the connection is immediately
     * destroyed.
     *
     * @param host
     * @param port
     * @param callback
     */
    connect = function (host, port, callback) {
        var socket = new Socket(),
            called,

            done = function () {
                !called && callback.apply(this, arguments);
                called = true;
                this.destroy();
            };

        socket.setTimeout(SOCKET_TIMEOUT, done);
        socket.once('connect', done);
        socket.once('error', done);
        socket.connect(port, host);
        socket = null;
    },

    /**
     * Override DNS lookups in Node, to handle localhost as a special case.
     * Chrome tries connecting to IPv6 by default, so we try the same thing.
     *
     * @param request
     * @param hostname
     * @param options
     * @param callback
     */
    lookup = function (request, hostname, options, callback) {
        if (hostname !== 'localhost') {
            return dns.lookup(hostname, options, callback);
        }

        async.waterfall([
            function (next) {
                // Try checking if we can connect to IPv6 localhost ('::1')
                connect(LOCAL_IPV6, port, function (err) {
                    next(null, !err);
                });
            },
            function (result, next) {
                return next(null, result ? LOCAL_IPV6 : LOCAL_IPV4, result ? 6 : 4);
            }
        ], function (err, ip, family) {
            callback(null, ip, family);
        });
    };

module.exports = function (options, callback) {
    var request = options.request,
        // todo: ensure that the sdk trims the host
        hostname = request.url && request.url.getHost().toLowerCase(),
        port;


    if (hostname === LOCALHOST) {<commit_msg>use constant instead of creating a string<commit_after>var _ = require('lodash'),
    async = require('async'),
    requests = require('request'),
    dns = require('dns'),
    Socket = require('net').Socket,

    LOCAL_IPV6 = '::1',
    LOCAL_IPV4 = '127.0.0.1',
    LOCALHOST = 'localhost',
    SOCKET_TIMEOUT = 500,

    /**
     * Tries to make a TCP connection to the given host and port. If successful, the connection is immediately
     * destroyed.
     *
     * @param host
     * @param port
     * @param callback
     */
    connect = function (host, port, callback) {
        var socket = new Socket(),
            called,

            done = function () {
                !called && callback.apply(this, arguments);
                called = true;
                this.destroy();
            };

        socket.setTimeout(SOCKET_TIMEOUT, done);
        socket.once('connect', done);
        socket.once('error', done);
        socket.connect(port, host);
        socket = null;
    },

    /**
     * Override DNS lookups in Node, to handle localhost as a special case.
     * Chrome tries connecting to IPv6 by default, so we try the same thing.
     *
     * @param request
     * @param hostname
     * @param options
     * @param callback
     */
    lookup = function (request, hostname, options, callback) {
        if (hostname !== LOCALHOST) {
            return dns.lookup(hostname, options, callback);
        }

        async.waterfall([
            function (next) {
                // Try checking if we can connect to IPv6 localhost ('::1')
                connect(LOCAL_IPV6, port, function (err) {
                    next(null, !err);
                });
            },
            function (result, next) {
                return next(null, result ? LOCAL_IPV6 : LOCAL_IPV4, result ? 6 : 4);
            }
        ], function (err, ip, family) {
            callback(null, ip, family);
        });
    };

module.exports = function (options, callback) {
    var request = options.request,
        // todo: ensure that the sdk trims the host
        hostname = request.url && request.url.getHost().toLowerCase(),
        port;


    if (hostname === LOCALHOST) {
{'fraction_non_alphanumeric': 0.12018348623853212, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 1.81536475145255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '341946', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1179, 'n_words': 358}