<commit_before>
var url = require('url')
var debug = require('debug')
  , chalk = require('chalk')
  , prettyjson = require('prettyjson')

var is = {
  req: debug('req'),
  res: debug('res'),
  options: debug('options') || debug('options:http'),
  raw: debug('options:raw')
}
var options = {
  keysColor: 'blue',
  stringColor: 'grey'
}


function log (req) {
  req.on('options', function (_options) {
    if (is.raw.name === 'enabled') {
      console.log(chalk.gray.inverse('options'))
      console.log(prettyjson.render(_options, options, 4))
    }
  })

  req.on('request', function (req, _options) {
    if (is.options.name === 'enabled') {
      console.log(chalk.gray.inverse('options'))
      console.log(prettyjson.render(_options, options, 4))
    }

    if (is.req.name === 'enabled') {
      var mt = method(req.method)
      console.log(
        chalk.yellow.inverse('req'),
        mt(req.method),
        chalk.yellow(uri(req)))
      // console.log(req._headers) contains the 'host' header as well
      // but all headers are lowervase'd
      console.log(prettyjson.render(_options.headers, options, 4))
    }
  })

  req.on('response', function (res) {
    var code = res.statusCode

    var st = status(res.statusCode)
    if (is.res.name === 'enabled') {
      console.log(
        st.inverse('res'),
        st(res.statusCode + ' ' + res.statusMessage))
      console.log(prettyjson.render(res.headers, options, 4))
    }
  })
}

function method (verb) {
  if (/GET/.test(verb)) {
    return chalk.green
  }
  else if (/POST/.test(verb)) {
    return chalk.cyan
  }
  else if (/PUT/.test(verb)) {
    return chalk.cyan
  }
  else if (/DELETE/.test(verb)) {
    return chalk.red
  }
  else if (/HEAD|OPTIONS|CONNECT/.test(verb)) {
    return chalk.yellow
  }
  else if (/TRACE/.test(verb)) {
    return chalk.gray
  }
}

function uri (req) {
  return req.agent.protocol + '//' + req._headers.host +
    (req.path === '/' ? '' : req.path)

  // return url.format({
  //   protocol: req.agent.protocol,
  //   host: req._headers.host,
  //   pathname: (req.path === '/' ? '' : req.path)
  // })
}

function status (code) {
  if (code >= 100 && code <= 199) {
    return chalk.white
  }
  else if (code >= 200 && code <= 299) {
    return chalk.green
  }
  else if (code >= 300 && code <= 399) {
    return chalk.yellow
  }
  else if (code >= 400 && code <= 499) {
    return chalk.red
  }
  else if (code >= 500 && code <= 599) {
    return chalk.red.bold
  }
}

module.exports = log
<commit_msg>Temporary workaround for the request headers case issue<commit_after>
var url = require('url')
var debug = require('debug')
  , chalk = require('chalk')
  , prettyjson = require('prettyjson')
  , extend = require('extend')

var is = {
  req: debug('req'),
  res: debug('res'),
  options: debug('options') || debug('options:http'),
  raw: debug('options:raw'),
  body: debug('body')
}
var options = {
  keysColor: 'blue',
  stringColor: 'grey'
}


function log (req) {
  req.on('options', function (_options) {
    if (is.raw.name === 'enabled') {
      console.log(chalk.gray.inverse('options'))
      console.log(prettyjson.render(_options, options, 4))
    }
  })

  req.on('request', function (req, _options) {
    if (is.options.name === 'enabled') {
      console.log(chalk.gray.inverse('options'))
      console.log(prettyjson.render(_options, options, 4))
    }

    if (is.req.name === 'enabled') {
      var mt = method(req.method)
      console.log(
        chalk.yellow.inverse('req'),
        mt(req.method),
        chalk.yellow(uri(req))
      )

      // TODO: refactor
      // console.log(req._headers) contains the 'host' header as well
      // but all headers are lowervase'd
      var headers = {}
      extend(true, headers, _options.headers)

      var h = Object.keys(_options.headers).map(function (key) {
        return key.toLowerCase()
      })
      Object.keys(req._headers).filter(function (key) {
        return h.indexOf(key) === -1
      })
      .forEach(function (key) {
        headers[key] = req._headers[key]
      })

      console.log(prettyjson.render(headers, options, 4))
    }

    if (is.body.name === 'enabled') {
      console.log(chalk.gray.inverse('body'), _options.body)
    }
  })

  req.on('response', function (res) {
    var code = res.statusCode

    var st = status(res.statusCode)
    if (is.res.name === 'enabled') {
      console.log(
        st.inverse('res'),
        st(res.statusCode + ' ' + res.statusMessage))
      console.log(prettyjson.render(res.headers, options, 4))
    }
  })

  req.on('callback', function (body) {
    if (is.body.name === 'enabled') {
      console.log(chalk.gray.inverse('body'), body)
    }
  })
}

function method (verb) {
  if (/GET/.test(verb)) {
    return chalk.green
  }
  else if (/POST/.test(verb)) {
    return chalk.cyan
  }
  else if (/PUT/.test(verb)) {
    return chalk.cyan
  }
  else if (/DELETE/.test(verb)) {
    return chalk.red
  }
  else if (/HEAD|OPTIONS|CONNECT/.test(verb)) {
    return chalk.yellow
  }
  else if (/TRACE/.test(verb)) {
    return chalk.gray
  }
}

function uri (req) {
  return req.agent.protocol + '//' + req._headers.host +
    (req.path === '/' ? '' : req.path)

  // return url.format({
  //   protocol: req.agent.protocol,
  //   host: req._headers.host,
  //   pathname: (req.path === '/' ? '' : req.path)
  // })
}

function status (code) {
  if (code >= 100 && code <= 199) {
    return chalk.white
  }
  else if (code >= 200 && code <= 299) {
    return chalk.green
  }
  else if (code >= 300 && code <= 399) {
    return chalk.yellow
  }
  else if (code >= 400 && code <= 499) {
    return chalk.red
  }
  else if (code >= 500 && code <= 599) {
    return chalk.red.bold
  }
}

module.exports = log

{'fraction_non_alphanumeric': 0.1779513888888889, 'fraction_numerical': 0.011979166666666667, 'mean_word_length': 2.58271144278607, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3452765', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1941, 'n_words': 424}