<commit_before>
var url = require('url')


exports.request = function (req, options) {
  updateURL(options)
}

exports.response = function (req, res, options) {
  updateURL(options)
}

function updateURL (options) {
  if (typeof options.proxy === 'string') {
    options.proxy = url.parse(options.proxy)
  }

  var absolute =
    options.proxy.protocol + '//' + options.url.host + options.url.path

  options.url.path = absolute

  options.headers.set('Host', options.url.hostname)

  options.url.hostname = options.proxy.hostname
  options.url.port = options.proxy.port
}<commit_msg>Add support for proxy authorization<commit_after>
var url = require('url')
var querystring = require('querystring')


exports.request = function (req, options) {
  updateURL(options)
}

exports.response = function (req, res, options) {
  updateURL(options)
}

function updateURL (options) {
  if (typeof options.proxy === 'string') {
    options.proxy = url.parse(options.proxy)
  }

  var absolute =
    options.proxy.protocol + '//' + options.url.host + options.url.path

  options.url.path = absolute

  options.headers.set('Host', options.url.hostname)

  options.url.hostname = options.proxy.hostname
  options.url.port = options.proxy.port


  if (options.proxy.auth && !options.headers.get('proxy-authorization')) {
    setAuthorization(options)
  }
}

function setAuthorization (options) {
  var proxyAuthPieces = options.proxy.auth.split(':').map(function (item) {
    return querystring.unescape(item)
  })
  var authHeader = 'Basic ' + toBase64(proxyAuthPieces.join(':'))
  options.headers.set('proxy-authorization', authHeader)
}

function toBase64 (str) {
  return (new Buffer(str || '', 'utf8')).toString('base64')
}
{'fraction_non_alphanumeric': 0.147024504084014, 'fraction_numerical': 0.004084014002333722, 'mean_word_length': 4.212765957446808, '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': '5407716', 'n_tokens_mistral': 553, 'n_tokens_neox': 542, 'n_words': 107}