<commit_before>var HTTP = require('http')
  , HTTPProxy = require('http-proxy')
  , URL = require('url')
  ;

var proxy = new HTTPProxy.RoutingProxy();

HTTP.createServer(function(request, response) {
  var innerURL = request.url.substr(1);
  var parsedURL = URL.parse(innerURL);
  request.url = innerURL.toLowerCase();

  proxy.proxyRequest(request, response, {
    host: parsedURL.hostname,
    port: 80,
  });
}).listen(process.env.PORT);<commit_msg>Don't crash and burn on bad URLs<commit_after>var HTTP = require('http')
  , HTTPProxy = require('http-proxy')
  , URL = require('url')
  ;

var proxy = new HTTPProxy.RoutingProxy();

HTTP.createServer(function(request, response) {
  var innerURL = request.url.substr(1);
  var parsedURL = URL.parse(innerURL);
  if (!parsedURL.hostname) {
    var body = 'Invalid URL ' + innerURL;
    response.writeHead(400, {
      'Content-Length': body.length,
      'Content-Type': 'text/plain'
    });
    response.write(body);
    response.end();
    return;
  }

  request.url = innerURL.toLowerCase();

  proxy.proxyRequest(request, response, {
    host: parsedURL.hostname,
    port: 80,
  });
}).listen(process.env.PORT);
{'fraction_non_alphanumeric': 0.15654405474764757, 'fraction_numerical': 0.007698887938408896, 'mean_word_length': 3.9159663865546217, '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': '5124583', 'n_tokens_mistral': 385, 'n_tokens_neox': 383, 'n_words': 76}