<commit_before>var cadence = require('cadence')
var delta = require('delta')
var extractOptions = require('./options')

module.exports = cadence(function (async, http, request, cancel) {
    var options = extractOptions(request)
    var client = http.request(options)
    client.once('error', listener('request'))
    function listener (direction) {
        return function (error) {
            // What do to about? http://stackoverflow.com/a/16995223/90123
            console.error(direction + ' error', {
                url: request.url,
                headers: request.headers,
            })
            console.log(error.stack)
        }
    }
    async(function () {
        var wait = delta(async()).ee(client).on('response')
        cancel.wait(function () { client.abort() })
        client.on('abort', function () {
            var error = new Error('socket hang up')
            error.code = 'ECONNRESET'
            wait.cancel([ error ])
        })
        if (request.timeout) {
            client.setTimeout(request.timeout, function () { cancel.unlatch() })
        }
        // TODO Fetch and Reqest can have the same `PassThrough`.
        request.input.pipe(client)
    }, function (response) {
        response.once('error', listener('response'))
        return [ response, client ]
    })
})
<commit_msg>Fix abort on 0.12.<commit_after>var cadence = require('cadence')
var delta = require('delta')
var extractOptions = require('./options')

module.exports = cadence(function (async, http, request, cancel) {
    var options = extractOptions(request)
    var client = http.request(options)
    client.once('error', listener('request'))
    function listener (direction) {
        return function (error) {
            // What do to about? http://stackoverflow.com/a/16995223/90123
            console.error(direction + ' error', {
                url: request.url,
                headers: request.headers,
            })
            console.log(error.stack)
        }
    }
    async(function () {
        var wait = delta(async()).ee(client).on('response')
        cancel.wait(function () {
            request.input.unpipe()
            client.abort()
            var error = new Error('socket hang up')
            error.code = 'ECONNRESET'
            wait.cancel([ error ])
        })
        if (request.timeout) {
            client.setTimeout(request.timeout, function () { cancel.unlatch() })
        }
        // TODO Fetch and Reqest can have the same `PassThrough`.
        request.input.pipe(client)
    }, function (response) {
        response.once('error', listener('response'))
        return [ response, client ]
    })
})

{'fraction_non_alphanumeric': 0.1350337584396099, 'fraction_numerical': 0.010877719429857465, 'mean_word_length': 2.156213017751479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1926942', 'n_tokens_mistral': 737, 'n_tokens_neox': 715, 'n_words': 164}