<commit_before>"use strict";

var 
  http = require('http'),
  httpProxy = require('http-proxy'),
  validUrl = require('valid-url'),
  url = require('url'),
  _ = require('lodash'),
  redisBackend = require('./redis-backend'),
  bunyan = require('bunyan');

var log = bunyan.createLogger({
    name: 'redbird',
});

function ReverseProxy(backend, opts){
  backend = backend || redisBackend();
  opts = opts || {};

  opts.port = opts.port || 8080;

  if(!(this instanceof ReverseProxy)){
    return new ReverseProxy(backend, opts);
  }

  //
  // Create a proxy server with custom application logic
  //
  var proxy = httpProxy.createProxyServer();

  //
  // Routing table.
  //
  var routing = this.routing = {};

  var server = require('http').createServer(function(req, res) {
    var target = getTarget(routing, req);
    if(target){
      proxy.web(req, res, { target: target });
    }else {
      notFound(res);
    }
  });

  //
  // Listen to the `upgrade` event and proxy the 
  // WebSocket requests as well.
  //
  server.on('upgrade', function (req, socket, head) {
    log.info({headers: req.headers, socket: socket, head: head}, "upgrade to websockets");
    var target = getTarget(routing, req);
    if(target){
      proxy.ws(req, socket, head, {target: target});
    }else{
      notFound(socket);
    }<commit_msg>removed socket and head logs<commit_after>"use strict";

var 
  http = require('http'),
  httpProxy = require('http-proxy'),
  validUrl = require('valid-url'),
  url = require('url'),
  _ = require('lodash'),
  redisBackend = require('./redis-backend'),
  bunyan = require('bunyan');

var log = bunyan.createLogger({
    name: 'redbird',
});

function ReverseProxy(backend, opts){
  backend = backend || redisBackend(); 
  // TODO: If no backend is specified just instantiate a static proxy.
  
  opts = opts || {};

  opts.port = opts.port || 8080;

  if(!(this instanceof ReverseProxy)){
    return new ReverseProxy(backend, opts);
  }

  //
  // Create a proxy server with custom application logic
  //
  var proxy = httpProxy.createProxyServer();

  //
  // Routing table.
  //
  var routing = this.routing = {};

  var server = require('http').createServer(function(req, res) {
    var target = getTarget(routing, req);
    if(target){
      proxy.web(req, res, { target: target });
    }else {
      notFound(res);
    }
  });

  //
  // Listen to the `upgrade` event and proxy the 
  // WebSocket requests as well.
  //
  server.on('upgrade', function (req, socket, head) {
    log.info({headers: req.headers}, "upgrade to websockets");
    var target = getTarget(routing, req);
    if(target){
      proxy.ws(req, socket, head, {target: target});
    }else{
      notFound(socket);
    }
{'fraction_non_alphanumeric': 0.1598240469208211, 'fraction_numerical': 0.002932551319648094, 'mean_word_length': 3.1099397590361444, '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': '4956909', 'n_tokens_mistral': 886, 'n_tokens_neox': 853, 'n_words': 227}